From f1bfd76bbb173e9c608610de1211d242e41bfbca Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Tue, 20 Jan 2015 18:52:18 -0500 Subject: [PATCH] Fixed some typos and added some examples --- src/bigint.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/bigint.rs b/src/bigint.rs index db7e3fd..389fa42 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -860,7 +860,7 @@ impl FromStrRadix for BigUint { impl BigUint { /// Creates and initializes a `BigUint`. /// - /// The digits are be in base 2^32. + /// The digits are in little-endian base 2^32. #[inline] pub fn new(mut digits: Vec) -> BigUint { // omit trailing zeros @@ -871,13 +871,23 @@ impl BigUint { /// Creates and initializes a `BigUint`. /// - /// The digits are be in base 2^32. + /// The digits are in little-endian base 2^32. #[inline] pub fn from_slice(slice: &[BigDigit]) -> BigUint { BigUint::new(slice.to_vec()) } /// Creates and initializes a `BigUint`. + /// + /// # Examples + /// + /// ``` + /// use num::bigint::{BigUint, ToBigUint}; + /// + /// assert_eq!(BigUint::parse_bytes("1234".as_bytes(), 10), ToBigUint::to_biguint(&1234)); + /// assert_eq!(BigUint::parse_bytes("ABCD".as_bytes(), 16), ToBigUint::to_biguint(&0xABCD)); + /// assert_eq!(BigUint::parse_bytes("G".as_bytes(), 16), None); + /// ``` #[inline] pub fn parse_bytes(buf: &[u8], radix: usize) -> Option { str::from_utf8(buf).ok().and_then(|s| FromStrRadix::from_str_radix(s, radix)) @@ -1553,7 +1563,7 @@ impl RandBigInt for R { impl BigInt { /// Creates and initializes a BigInt. /// - /// The digits are be in base 2^32. + /// The digits are in little-endian base 2^32. #[inline] pub fn new(sign: Sign, digits: Vec) -> BigInt { BigInt::from_biguint(sign, BigUint::new(digits)) @@ -1561,7 +1571,7 @@ impl BigInt { /// Creates and initializes a `BigInt`. /// - /// The digits are be in base 2^32. + /// The digits are in little-endian base 2^32. #[inline] pub fn from_biguint(sign: Sign, data: BigUint) -> BigInt { if sign == NoSign || data.is_zero() { @@ -1577,6 +1587,16 @@ impl BigInt { } /// Creates and initializes a `BigInt`. + /// + /// # Examples + /// + /// ``` + /// use num::bigint::{BigInt, ToBigInt}; + /// + /// assert_eq!(BigInt::parse_bytes("1234".as_bytes(), 10), ToBigInt::to_bigint(&1234)); + /// assert_eq!(BigInt::parse_bytes("ABCD".as_bytes(), 16), ToBigInt::to_bigint(&0xABCD)); + /// assert_eq!(BigInt::parse_bytes("G".as_bytes(), 16), None); + /// ``` #[inline] pub fn parse_bytes(buf: &[u8], radix: usize) -> Option { str::from_utf8(buf).ok().and_then(|s| FromStrRadix::from_str_radix(s, radix))