diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 32 |
1 files changed, 14 insertions, 18 deletions
@@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! A Big integer (signed version: `BigInt`, unsigned version: `BigUint`). +//! Big Integer Types for Rust //! -//! A `BigUint` is represented as a vector of `BigDigit`s. -//! A `BigInt` is a combination of `BigUint` and `Sign`. +//! * A [`BigUint`] is unsigned and represented as a vector of digits. +//! * A [`BigInt`] is signed and is a combination of [`BigUint`] and [`Sign`]. //! //! Common numerical operations are overloaded, so we can treat them //! the same way we treat other numbers. @@ -22,7 +22,6 @@ //! # fn main() { //! use num_bigint::BigUint; //! use num_traits::{Zero, One}; -//! use std::mem::replace; //! //! // Calculate large fibonacci numbers. //! fn fib(n: usize) -> BigUint { @@ -30,8 +29,8 @@ //! let mut f1: BigUint = One::one(); //! for _ in 0..n { //! let f2 = f0 + &f1; -//! // This is a low cost way of swapping f0 with f1 and f1 with f2. -//! f0 = replace(&mut f1, f2); +//! f0 = f1; +//! f1 = f2; //! } //! f0 //! } @@ -95,7 +94,7 @@ extern crate std; #[cfg(feature = "std")] mod std_alloc { pub(crate) use std::borrow::Cow; - #[cfg(any(feature = "quickcheck"))] + #[cfg(feature = "quickcheck")] pub(crate) use std::boxed::Box; pub(crate) use std::string::String; pub(crate) use std::vec::Vec; @@ -108,7 +107,7 @@ extern crate alloc; #[cfg(not(feature = "std"))] mod std_alloc { pub(crate) use alloc::borrow::Cow; - #[cfg(any(feature = "quickcheck"))] + #[cfg(feature = "quickcheck")] pub(crate) use alloc::boxed::Box; pub(crate) use alloc::string::String; pub(crate) use alloc::vec::Vec; @@ -202,9 +201,6 @@ impl<T> TryFromBigIntError<T> { /// Extract the original value, if available. The value will be available /// if the type before conversion was either [`BigInt`] or [`BigUint`]. - /// - /// [`BigInt`]: struct.BigInt.html - /// [`BigUint`]: struct.BigUint.html pub fn into_original(self) -> T { self.original } @@ -240,26 +236,26 @@ pub use crate::bigint::ToBigInt; pub use crate::bigrand::{RandBigInt, RandomBits, UniformBigInt, UniformBigUint}; mod big_digit { - /// A `BigDigit` is a `BigUint`'s composing element. + /// A [`BigDigit`] is a [`BigUint`]'s composing element. #[cfg(not(u64_digit))] pub(crate) type BigDigit = u32; #[cfg(u64_digit)] pub(crate) type BigDigit = u64; - /// A `DoubleBigDigit` is the internal type used to do the computations. Its - /// size is the double of the size of `BigDigit`. + /// A [`DoubleBigDigit`] is the internal type used to do the computations. Its + /// size is the double of the size of [`BigDigit`]. #[cfg(not(u64_digit))] pub(crate) type DoubleBigDigit = u64; #[cfg(u64_digit)] pub(crate) type DoubleBigDigit = u128; - /// A `SignedDoubleBigDigit` is the signed version of `DoubleBigDigit`. + /// A [`SignedDoubleBigDigit`] is the signed version of [`DoubleBigDigit`]. #[cfg(not(u64_digit))] pub(crate) type SignedDoubleBigDigit = i64; #[cfg(u64_digit)] pub(crate) type SignedDoubleBigDigit = i128; - // `DoubleBigDigit` size dependent + // [`DoubleBigDigit`] size dependent #[cfg(not(u64_digit))] pub(crate) const BITS: u8 = 32; #[cfg(u64_digit)] @@ -280,13 +276,13 @@ mod big_digit { (n & LO_MASK) as BigDigit } - /// Split one `DoubleBigDigit` into two `BigDigit`s. + /// Split one [`DoubleBigDigit`] into two [`BigDigit`]s. #[inline] pub(crate) fn from_doublebigdigit(n: DoubleBigDigit) -> (BigDigit, BigDigit) { (get_hi(n), get_lo(n)) } - /// Join two `BigDigit`s into one `DoubleBigDigit` + /// Join two [`BigDigit`]s into one [`DoubleBigDigit`]. #[inline] pub(crate) fn to_doublebigdigit(hi: BigDigit, lo: BigDigit) -> DoubleBigDigit { DoubleBigDigit::from(lo) | (DoubleBigDigit::from(hi) << BITS) |