diff --git a/benches/bigint.rs b/benches/bigint.rs index bba683b..a043e16 100644 --- a/benches/bigint.rs +++ b/benches/bigint.rs @@ -1,17 +1,17 @@ #![feature(test)] #![cfg(feature = "rand")] -extern crate test; extern crate num_bigint; -extern crate num_traits; extern crate num_integer; +extern crate num_traits; extern crate rand; +extern crate test; +use num_bigint::{BigInt, BigUint, RandBigInt}; +use num_traits::{FromPrimitive, Num, One, Pow, Zero}; +use rand::{SeedableRng, StdRng}; use std::mem::replace; use test::Bencher; -use num_bigint::{BigInt, BigUint, RandBigInt}; -use num_traits::{Zero, One, FromPrimitive, Num, Pow}; -use rand::{SeedableRng, StdRng}; fn get_rng() -> StdRng { let mut seed = [0; 32]; @@ -39,7 +39,7 @@ fn divide_bench(b: &mut Bencher, xbits: usize, ybits: usize) { fn factorial(n: usize) -> BigUint { let mut f: BigUint = One::one(); - for i in 1..(n+1) { + for i in 1..(n + 1) { let bu: BigUint = FromPrimitive::from_usize(i).unwrap(); f = f * bu; } @@ -307,21 +307,21 @@ fn pow_bench(b: &mut Bencher) { }); } - /// This modulus is the prime from the 2048-bit MODP DH group: /// https://tools.ietf.org/html/rfc3526#section-3 -const RFC3526_2048BIT_MODP_GROUP: &'static str = "\ - FFFFFFFF_FFFFFFFF_C90FDAA2_2168C234_C4C6628B_80DC1CD1\ - 29024E08_8A67CC74_020BBEA6_3B139B22_514A0879_8E3404DD\ - EF9519B3_CD3A431B_302B0A6D_F25F1437_4FE1356D_6D51C245\ - E485B576_625E7EC6_F44C42E9_A637ED6B_0BFF5CB6_F406B7ED\ - EE386BFB_5A899FA5_AE9F2411_7C4B1FE6_49286651_ECE45B3D\ - C2007CB8_A163BF05_98DA4836_1C55D39A_69163FA8_FD24CF5F\ - 83655D23_DCA3AD96_1C62F356_208552BB_9ED52907_7096966D\ - 670C354E_4ABC9804_F1746C08_CA18217C_32905E46_2E36CE3B\ - E39E772C_180E8603_9B2783A2_EC07A28F_B5C55DF0_6F4C52C9\ - DE2BCBF6_95581718_3995497C_EA956AE5_15D22618_98FA0510\ - 15728E5A_8AACAA68_FFFFFFFF_FFFFFFFF"; +const RFC3526_2048BIT_MODP_GROUP: &'static str = + "\ + FFFFFFFF_FFFFFFFF_C90FDAA2_2168C234_C4C6628B_80DC1CD1\ + 29024E08_8A67CC74_020BBEA6_3B139B22_514A0879_8E3404DD\ + EF9519B3_CD3A431B_302B0A6D_F25F1437_4FE1356D_6D51C245\ + E485B576_625E7EC6_F44C42E9_A637ED6B_0BFF5CB6_F406B7ED\ + EE386BFB_5A899FA5_AE9F2411_7C4B1FE6_49286651_ECE45B3D\ + C2007CB8_A163BF05_98DA4836_1C55D39A_69163FA8_FD24CF5F\ + 83655D23_DCA3AD96_1C62F356_208552BB_9ED52907_7096966D\ + 670C354E_4ABC9804_F1746C08_CA18217C_32905E46_2E36CE3B\ + E39E772C_180E8603_9B2783A2_EC07A28F_B5C55DF0_6F4C52C9\ + DE2BCBF6_95581718_3995497C_EA956AE5_15D22618_98FA0510\ + 15728E5A_8AACAA68_FFFFFFFF_FFFFFFFF"; #[bench] fn modpow(b: &mut Bencher) { diff --git a/benches/factorial.rs b/benches/factorial.rs index fc79845..4392df8 100644 --- a/benches/factorial.rs +++ b/benches/factorial.rs @@ -11,7 +11,11 @@ use test::Bencher; #[bench] fn factorial_mul_biguint(b: &mut Bencher) { - b.iter(|| (1u32..1000).map(BigUint::from).fold(BigUint::one(), Mul::mul)); + b.iter(|| { + (1u32..1000) + .map(BigUint::from) + .fold(BigUint::one(), Mul::mul) + }); } #[bench] @@ -25,7 +29,12 @@ fn factorial_mul_u32(b: &mut Bencher) { #[bench] fn factorial_div_biguint(b: &mut Bencher) { let n: BigUint = (1u32..1000).fold(BigUint::one(), Mul::mul); - b.iter(|| (1u32..1000).rev().map(BigUint::from).fold(n.clone(), Div::div)); + b.iter(|| { + (1u32..1000) + .rev() + .map(BigUint::from) + .fold(n.clone(), Div::div) + }); } #[bench] diff --git a/benches/gcd.rs b/benches/gcd.rs index 4815044..5fe5260 100644 --- a/benches/gcd.rs +++ b/benches/gcd.rs @@ -1,17 +1,17 @@ #![feature(test)] #![cfg(feature = "rand")] -extern crate test; extern crate num_bigint; extern crate num_integer; extern crate num_traits; extern crate rand; +extern crate test; -use test::Bencher; use num_bigint::{BigUint, RandBigInt}; use num_integer::Integer; use num_traits::Zero; use rand::{SeedableRng, StdRng}; +use test::Bencher; fn get_rng() -> StdRng { let mut seed = [0; 32]; @@ -31,7 +31,6 @@ fn bench(b: &mut Bencher, bits: usize, gcd: fn(&BigUint, &BigUint) -> BigUint) { b.iter(|| gcd(&x, &y)); } - fn euclid(x: &BigUint, y: &BigUint) -> BigUint { // Use Euclid's algorithm let mut m = x.clone(); @@ -64,7 +63,6 @@ fn gcd_euclid_4096(b: &mut Bencher) { bench(b, 4096, euclid); } - // Integer for BigUint now uses Stein for gcd #[bench] diff --git a/benches/shootout-pidigits.rs b/benches/shootout-pidigits.rs index 2d3b221..515710d 100644 --- a/benches/shootout-pidigits.rs +++ b/benches/shootout-pidigits.rs @@ -42,12 +42,12 @@ extern crate num_bigint; extern crate num_integer; extern crate num_traits; -use std::str::FromStr; use std::io; +use std::str::FromStr; use num_bigint::BigInt; use num_integer::Integer; -use num_traits::{FromPrimitive, ToPrimitive, One, Zero}; +use num_traits::{FromPrimitive, One, ToPrimitive, Zero}; struct Context { numer: BigInt, @@ -69,11 +69,13 @@ impl Context { } fn extract_digit(&self) -> i32 { - if self.numer > self.accum {return -1;} - let (q, r) = - (&self.numer * Context::from_i32(3) + &self.accum) - .div_rem(&self.denom); - if r + &self.numer >= self.denom {return -1;} + if self.numer > self.accum { + return -1; + } + let (q, r) = (&self.numer * Context::from_i32(3) + &self.accum).div_rem(&self.denom); + if r + &self.numer >= self.denom { + return -1; + } q.to_i32().unwrap() } @@ -96,24 +98,30 @@ fn pidigits(n: isize, out: &mut io::Write) -> io::Result<()> { let mut k = 0; let mut context = Context::new(); - for i in 1..(n+1) { + for i in 1..(n + 1) { let mut d; loop { k += 1; context.next_term(k); d = context.extract_digit(); - if d != -1 {break;} + if d != -1 { + break; + } } try!(write!(out, "{}", d)); - if i % 10 == 0 { try!(write!(out, "\t:{}\n", i)); } + if i % 10 == 0 { + try!(write!(out, "\t:{}\n", i)); + } context.eliminate_digit(d); } let m = n % 10; if m != 0 { - for _ in m..10 { try!(write!(out, " ")); } + for _ in m..10 { + try!(write!(out, " ")); + } try!(write!(out, "\t:{}\n", n)); } Ok(()) @@ -126,7 +134,7 @@ fn main() { let n = if args.len() < 2 { DEFAULT_DIGITS } else if args[1] == "--bench" { - return pidigits(DEFAULT_DIGITS, &mut std::io::sink()).unwrap() + return pidigits(DEFAULT_DIGITS, &mut std::io::sink()).unwrap(); } else { FromStr::from_str(&args[1]).unwrap() }; diff --git a/src/algorithms.rs b/src/algorithms.rs index 008fcd2..90ef702 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -1,10 +1,10 @@ use std::borrow::Cow; use std::cmp; -use std::cmp::Ordering::{self, Less, Greater, Equal}; +use std::cmp::Ordering::{self, Equal, Greater, Less}; use std::iter::repeat; use std::mem; use traits; -use traits::{Zero, One}; +use traits::{One, Zero}; use biguint::BigUint; @@ -95,7 +95,9 @@ pub fn __add2(a: &mut [BigDigit], b: &[BigDigit]) -> BigDigit { if carry != 0 { for a in a_hi { *a = adc(*a, 0, &mut carry); - if carry == 0 { break } + if carry == 0 { + break; + } } } @@ -127,13 +129,17 @@ pub fn sub2(a: &mut [BigDigit], b: &[BigDigit]) { if borrow != 0 { for a in a_hi { *a = sbb(*a, 0, &mut borrow); - if borrow == 0 { break } + if borrow == 0 { + break; + } } } // note: we're _required_ to fail on underflow - assert!(borrow == 0 && b_hi.iter().all(|x| *x == 0), - "Cannot subtract b from a because b is larger than a."); + assert!( + borrow == 0 && b_hi.iter().all(|x| *x == 0), + "Cannot subtract b from a because b is larger than a." + ); } // Only for the Sub impl. `a` and `b` must have same length. @@ -162,8 +168,10 @@ pub fn sub2rev(a: &[BigDigit], b: &mut [BigDigit]) { assert!(a_hi.is_empty()); // note: we're _required_ to fail on underflow - assert!(borrow == 0 && b_hi.iter().all(|x| *x == 0), - "Cannot subtract b from a because b is larger than a."); + assert!( + borrow == 0 && b_hi.iter().all(|x| *x == 0), + "Cannot subtract b from a because b is larger than a." + ); } pub fn sub_sign(a: &[BigDigit], b: &[BigDigit]) -> (Sign, BigUint) { @@ -210,11 +218,7 @@ pub fn mac_digit(acc: &mut [BigDigit], b: &[BigDigit], c: BigDigit) { /// Three argument multiply accumulate: /// acc += b * c fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { - let (x, y) = if b.len() < c.len() { - (b, c) - } else { - (c, b) - }; + let (x, y) = if b.len() < c.len() { (b, c) } else { (c, b) }; // We use three algorithms for different input sizes. // @@ -317,8 +321,8 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { // Not required, but the adds go faster if we drop any unneeded 0s from the end: p.normalize(); - add2(&mut acc[b..], &p.data[..]); - add2(&mut acc[b * 2..], &p.data[..]); + add2(&mut acc[b..], &p.data[..]); + add2(&mut acc[b * 2..], &p.data[..]); // Zero out p before the next multiply: p.data.truncate(0); @@ -328,8 +332,8 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { mac3(&mut p.data[..], x0, y0); p.normalize(); - add2(&mut acc[..], &p.data[..]); - add2(&mut acc[b..], &p.data[..]); + add2(&mut acc[..], &p.data[..]); + add2(&mut acc[b..], &p.data[..]); // p1 = (x1 - x0) * (y1 - y0) // We do this one last, since it may be negative and acc can't ever be negative: @@ -337,7 +341,7 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { let (j1_sign, j1) = sub_sign(y1, y0); match j0_sign * j1_sign { - Plus => { + Plus => { p.data.truncate(0); p.data.extend(repeat(0).take(len)); @@ -345,13 +349,12 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { p.normalize(); sub2(&mut acc[b..], &p.data[..]); - }, - Minus => { + } + Minus => { mac3(&mut acc[b..], &j0.data[..], &j1.data[..]); - }, - NoSign => (), + } + NoSign => (), } - } else { // Toom-3 multiplication: // @@ -361,7 +364,7 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { // The general idea is to treat the large integers digits as // polynomials of a certain degree and determine the coefficients/digits // of the product of the two via interpolation of the polynomial product. - let i = y.len()/3 + 1; + let i = y.len() / 3 + 1; let x0_len = cmp::min(x.len(), i); let x1_len = cmp::min(x.len() - x0_len, i); @@ -432,7 +435,7 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { let r2 = &p2 * &q2; // w(-2) - let r3 = ((p2 + x2)*2 - x0) * ((q2 + y2)*2 - y0); + let r3 = ((p2 + x2) * 2 - x0) * ((q2 + y2) * 2 - y0); // Evaluating these points gives us the following system of linear equations. // @@ -456,14 +459,18 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { let mut comp3: BigInt = (r3 - &r1) / 3; let mut comp1: BigInt = (r1 - &r2) / 2; let mut comp2: BigInt = r2 - &r0; - comp3 = (&comp2 - comp3)/2 + &r4*2; + comp3 = (&comp2 - comp3) / 2 + &r4 * 2; comp2 = comp2 + &comp1 - &r4; comp1 = comp1 - &comp3; // Recomposition. The coefficients of the polynomial are now known. // // Evaluate at w(t) where t is our given base to get the result. - let result = r0 + (comp1 << 32*i) + (comp2 << 2*32*i) + (comp3 << 3*32*i) + (r4 << 4*32*i); + let result = r0 + + (comp1 << 32 * i) + + (comp2 << 2 * 32 * i) + + (comp3 << 3 * 32 * i) + + (r4 << 4 * 32 * i); let result_pos = result.to_biguint().unwrap(); add2(&mut acc[..], &result_pos.data); } @@ -533,13 +540,17 @@ pub fn div_rem(u: &BigUint, d: &BigUint) -> (BigUint, BigUint) { let bn = *b.data.last().unwrap(); let q_len = a.data.len() - b.data.len() + 1; - let mut q = BigUint { data: vec![0; q_len] }; + let mut q = BigUint { + data: vec![0; q_len], + }; // We reuse the same temporary to avoid hitting the allocator in our inner loop - this is // sized to hold a0 (in the common case; if a particular digit of the quotient is zero a0 // can be bigger). // - let mut tmp = BigUint { data: Vec::with_capacity(2) }; + let mut tmp = BigUint { + data: Vec::with_capacity(2), + }; for j in (0..q_len).rev() { /* @@ -678,9 +689,9 @@ pub fn cmp_slice(a: &[BigDigit], b: &[BigDigit]) -> Ordering { #[cfg(test)] mod algorithm_tests { use big_digit::BigDigit; - use {BigUint, BigInt}; - use Sign::Plus; use traits::Num; + use Sign::Plus; + use {BigInt, BigUint}; #[test] fn test_sub_sign() { diff --git a/src/bigint.rs b/src/bigint.rs index 520e37d..8347e04 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -1,24 +1,27 @@ -use std::default::Default; -use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub, - AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, - MulAssign, RemAssign, ShlAssign, ShrAssign, SubAssign}; -use std::str::{self, FromStr}; -use std::fmt; -use std::mem; -use std::cmp::Ordering::{self, Less, Greater, Equal}; -use std::{i64, u64}; -#[cfg(has_i128)] -use std::{i128, u128}; #[allow(deprecated, unused_imports)] use std::ascii::AsciiExt; +use std::cmp::Ordering::{self, Equal, Greater, Less}; +use std::default::Default; +use std::fmt; use std::iter::{Product, Sum}; +use std::mem; +use std::ops::{ + Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign, + Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign, +}; +use std::str::{self, FromStr}; +#[cfg(has_i128)] +use std::{i128, u128}; +use std::{i64, u64}; #[cfg(feature = "serde")] use serde; use integer::{Integer, Roots}; -use traits::{ToPrimitive, FromPrimitive, Num, CheckedAdd, CheckedSub, - CheckedMul, CheckedDiv, Signed, Zero, One, Pow}; +use traits::{ + CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Num, One, Pow, Signed, + ToPrimitive, Zero, +}; use self::Sign::{Minus, NoSign, Plus}; @@ -28,8 +31,8 @@ use biguint; use biguint::to_str_radix_reversed; use biguint::{BigUint, IntDigits}; -use UsizePromotion; use IsizePromotion; +use UsizePromotion; /// A Sign is a `BigInt`'s composing element. #[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone, Debug, Hash)] @@ -69,7 +72,8 @@ impl Mul for Sign { #[cfg(feature = "serde")] impl serde::Serialize for Sign { fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer + where + S: serde::Serializer, { // Note: do not change the serialization format, or it may break // forward and backward compatibility of serialized data! @@ -84,7 +88,8 @@ impl serde::Serialize for Sign { #[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for Sign { fn deserialize(deserializer: D) -> Result - where D: serde::Deserializer<'de> + where + D: serde::Deserializer<'de>, { use serde::de::Error; use serde::de::Unexpected; @@ -235,11 +240,7 @@ impl Not for BigInt { } Minus => { self.data -= 1u32; - self.sign = if self.data.is_zero() { - NoSign - } else { - Plus - }; + self.sign = if self.data.is_zero() { NoSign } else { Plus }; } } self @@ -302,7 +303,7 @@ fn bitand_neg_neg(a: &mut Vec, b: &[BigDigit]) { } debug_assert!(a.len() > b.len() || carry_a == 0); debug_assert!(b.len() > a.len() || carry_b == 0); - if a.len() > b.len() { + if a.len() > b.len() { for ai in a[b.len()..].iter_mut() { let twos_a = negate_carry(*ai, &mut carry_a); *ai = negate_carry(twos_a, &mut carry_and); @@ -709,10 +710,9 @@ impl ShlAssign for BigInt { // Negative values need a rounding adjustment if there are any ones in the // bits that are getting shifted out. fn shr_round_down(i: &BigInt, rhs: usize) -> bool { - i.is_negative() && - biguint::trailing_zeros(&i.data) - .map(|n| n < rhs) - .unwrap_or(false) + i.is_negative() && biguint::trailing_zeros(&i.data) + .map(|n| n < rhs) + .unwrap_or(false) } impl Shr for BigInt { @@ -811,7 +811,6 @@ impl Signed for BigInt { } } - /// Help function for pow /// /// Computes the effect of the exponent on the sign. @@ -847,7 +846,7 @@ macro_rules! pow_impl { BigInt::from_biguint(powsign(self.sign, rhs), (&self.data).pow(rhs)) } } - } + }; } pow_impl!(u8); @@ -858,7 +857,6 @@ pow_impl!(usize); #[cfg(has_i128)] pow_impl!(u128); - // A convenience method for getting the absolute value of an i32 in a u32. #[inline] fn i32_abs_as_u32(a: i32) -> u32 { @@ -888,15 +886,13 @@ macro_rules! bigint_add { (_, NoSign) => $a_owned, (NoSign, _) => $b_owned, // same sign => keep the sign with the sum of magnitudes - (Plus, Plus) | (Minus, Minus) => - BigInt::from_biguint($a.sign, $a_data + $b_data), + (Plus, Plus) | (Minus, Minus) => BigInt::from_biguint($a.sign, $a_data + $b_data), // opposite signs => keep the sign of the larger with the difference of magnitudes - (Plus, Minus) | (Minus, Plus) => - match $a.data.cmp(&$b.data) { - Less => BigInt::from_biguint($b.sign, $b_data - $a_data), - Greater => BigInt::from_biguint($a.sign, $a_data - $b_data), - Equal => Zero::zero(), - }, + (Plus, Minus) | (Minus, Plus) => match $a.data.cmp(&$b.data) { + Less => BigInt::from_biguint($b.sign, $b_data - $a_data), + Greater => BigInt::from_biguint($a.sign, $a_data - $b_data), + Equal => Zero::zero(), + }, } }; } @@ -906,12 +902,14 @@ impl<'a, 'b> Add<&'b BigInt> for &'a BigInt { #[inline] fn add(self, other: &BigInt) -> BigInt { - bigint_add!(self, - self.clone(), - &self.data, - other, - other.clone(), - &other.data) + bigint_add!( + self, + self.clone(), + &self.data, + other, + other.clone(), + &other.data + ) } } @@ -964,12 +962,11 @@ impl Add for BigInt { match self.sign { NoSign => From::from(other), Plus => BigInt::from_biguint(Plus, self.data + other), - Minus => - match self.data.cmp(&From::from(other)) { - Equal => Zero::zero(), - Less => BigInt::from_biguint(Plus, other - self.data), - Greater => BigInt::from_biguint(Minus, self.data - other), - } + Minus => match self.data.cmp(&From::from(other)) { + Equal => Zero::zero(), + Less => BigInt::from_biguint(Plus, other - self.data), + Greater => BigInt::from_biguint(Minus, self.data - other), + }, } } } @@ -989,12 +986,11 @@ impl Add for BigInt { match self.sign { NoSign => From::from(other), Plus => BigInt::from_biguint(Plus, self.data + other), - Minus => - match self.data.cmp(&From::from(other)) { - Equal => Zero::zero(), - Less => BigInt::from_biguint(Plus, other - self.data), - Greater => BigInt::from_biguint(Minus, self.data - other), - } + Minus => match self.data.cmp(&From::from(other)) { + Equal => Zero::zero(), + Less => BigInt::from_biguint(Plus, other - self.data), + Greater => BigInt::from_biguint(Minus, self.data - other), + }, } } } @@ -1082,12 +1078,14 @@ impl<'a, 'b> Sub<&'b BigInt> for &'a BigInt { #[inline] fn sub(self, other: &BigInt) -> BigInt { - bigint_sub!(self, - self.clone(), - &self.data, - other, - other.clone(), - &other.data) + bigint_sub!( + self, + self.clone(), + &self.data, + other, + other.clone(), + &other.data + ) } } @@ -1140,12 +1138,11 @@ impl Sub for BigInt { match self.sign { NoSign => BigInt::from_biguint(Minus, From::from(other)), Minus => BigInt::from_biguint(Minus, self.data + other), - Plus => - match self.data.cmp(&From::from(other)) { - Equal => Zero::zero(), - Greater => BigInt::from_biguint(Plus, self.data - other), - Less => BigInt::from_biguint(Minus, other - self.data), - } + Plus => match self.data.cmp(&From::from(other)) { + Equal => Zero::zero(), + Greater => BigInt::from_biguint(Plus, self.data - other), + Less => BigInt::from_biguint(Minus, other - self.data), + }, } } } @@ -1174,12 +1171,11 @@ impl Sub for BigInt { match self.sign { NoSign => BigInt::from_biguint(Minus, From::from(other)), Minus => BigInt::from_biguint(Minus, self.data + other), - Plus => - match self.data.cmp(&From::from(other)) { - Equal => Zero::zero(), - Greater => BigInt::from_biguint(Plus, self.data - other), - Less => BigInt::from_biguint(Minus, other - self.data), - } + Plus => match self.data.cmp(&From::from(other)) { + Equal => Zero::zero(), + Greater => BigInt::from_biguint(Plus, self.data - other), + Less => BigInt::from_biguint(Minus, other - self.data), + }, } } } @@ -1852,8 +1848,11 @@ impl Integer for BigInt { impl Roots for BigInt { fn nth_root(&self, n: u32) -> Self { - assert!(!(self.is_negative() && n.is_even()), - "root of degree {} is imaginary", n); + assert!( + !(self.is_negative() && n.is_even()), + "root of degree {} is imaginary", + n + ); BigInt::from_biguint(self.sign, self.data.nth_root(n)) } @@ -1875,18 +1874,16 @@ impl ToPrimitive for BigInt { match self.sign { Plus => self.data.to_i64(), NoSign => Some(0), - Minus => { - self.data.to_u64().and_then(|n| { - let m: u64 = 1 << 63; - if n < m { - Some(-(n as i64)) - } else if n == m { - Some(i64::MIN) - } else { - None - } - }) - } + Minus => self.data.to_u64().and_then(|n| { + let m: u64 = 1 << 63; + if n < m { + Some(-(n as i64)) + } else if n == m { + Some(i64::MIN) + } else { + None + } + }), } } @@ -1896,18 +1893,16 @@ impl ToPrimitive for BigInt { match self.sign { Plus => self.data.to_i128(), NoSign => Some(0), - Minus => { - self.data.to_u128().and_then(|n| { - let m: u128 = 1 << 127; - if n < m { - Some(-(n as i128)) - } else if n == m { - Some(i128::MIN) - } else { - None - } - }) - } + Minus => self.data.to_u128().and_then(|n| { + let m: u128 = 1 << 127; + if n < m { + Some(-(n as i128)) + } else if n == m { + Some(i128::MIN) + } else { + None + } + }), } } @@ -1932,24 +1927,16 @@ impl ToPrimitive for BigInt { #[inline] fn to_f32(&self) -> Option { - self.data.to_f32().map(|n| { - if self.sign == Minus { - -n - } else { - n - } - }) + self.data + .to_f32() + .map(|n| if self.sign == Minus { -n } else { n }) } #[inline] fn to_f64(&self) -> Option { - self.data.to_f64().map(|n| { - if self.sign == Minus { - -n - } else { - n - } - }) + self.data + .to_f64() + .map(|n| if self.sign == Minus { -n } else { n }) } } @@ -2025,7 +2012,7 @@ macro_rules! impl_bigint_from_int { BigInt::from(n as i64) } } - } + }; } impl_bigint_from_int!(i8); @@ -2070,7 +2057,7 @@ macro_rules! impl_bigint_from_uint { BigInt::from(n as u64) } } - } + }; } impl_bigint_from_uint!(u8); @@ -2121,7 +2108,8 @@ impl IntDigits for BigInt { #[cfg(feature = "serde")] impl serde::Serialize for BigInt { fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer + where + S: serde::Serializer, { // Note: do not change the serialization format, or it may break // forward and backward compatibility of serialized data! @@ -2132,7 +2120,8 @@ impl serde::Serialize for BigInt { #[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for BigInt { fn deserialize(deserializer: D) -> Result - where D: serde::Deserializer<'de> + where + D: serde::Deserializer<'de>, { let (sign, data) = serde::Deserialize::deserialize(deserializer)?; Ok(BigInt::from_biguint(sign, data)) @@ -2170,9 +2159,9 @@ impl biguint::ToBigUint for BigInt { #[inline] fn to_biguint(&self) -> Option { match self.sign() { - Plus => Some(self.data.clone()), - NoSign => Some(Zero::zero()), - Minus => None, + Plus => Some(self.data.clone()), + NoSign => Some(Zero::zero()), + Minus => None, } } } @@ -2185,7 +2174,7 @@ macro_rules! impl_to_bigint { $from_ty(*self) } } - } + }; } impl_to_bigint!(isize, FromPrimitive::from_isize); @@ -2341,7 +2330,9 @@ impl BigInt { /// ``` #[inline] pub fn parse_bytes(buf: &[u8], radix: u32) -> Option { - str::from_utf8(buf).ok().and_then(|s| BigInt::from_str_radix(s, radix).ok()) + str::from_utf8(buf) + .ok() + .and_then(|s| BigInt::from_str_radix(s, radix).ok()) } /// Creates and initializes a `BigInt`. Each u8 of the input slice is @@ -2452,7 +2443,8 @@ impl BigInt { pub fn to_signed_bytes_le(&self) -> Vec { let mut bytes = self.data.to_bytes_le(); let last_byte = bytes.last().map(|v| *v).unwrap_or(0); - if last_byte > 0x7f && !(last_byte == 0x80 && bytes.iter().rev().skip(1).all(Zero::is_zero)) { + if last_byte > 0x7f && !(last_byte == 0x80 && bytes.iter().rev().skip(1).all(Zero::is_zero)) + { // msb used by magnitude, extend by 1 byte bytes.push(0); } @@ -2588,7 +2580,10 @@ impl BigInt { /// /// Panics if the exponent is negative or the modulus is zero. pub fn modpow(&self, exponent: &Self, modulus: &Self) -> Self { - assert!(!exponent.is_negative(), "negative exponentiation is not supported!"); + assert!( + !exponent.is_negative(), + "negative exponentiation is not supported!" + ); assert!(!modulus.is_zero(), "divide by zero!"); let result = self.data.modpow(&exponent.data, &modulus.data); @@ -2646,7 +2641,8 @@ fn twos_complement_be(digits: &mut [u8]) { /// starting from the least significant byte. #[inline] fn twos_complement<'a, I>(digits: I) - where I: IntoIterator +where + I: IntoIterator, { let mut carry = true; for d in digits { @@ -2658,7 +2654,6 @@ fn twos_complement<'a, I>(digits: I) } } - #[test] fn test_from_biguint() { fn check(inp_s: Sign, inp_n: usize, ans_s: Sign, ans_n: usize) { diff --git a/src/bigrand.rs b/src/bigrand.rs index 077d744..4a13b29 100644 --- a/src/bigrand.rs +++ b/src/bigrand.rs @@ -1,7 +1,7 @@ //! Randomization of big integers -use rand::prelude::*; use rand::distributions::uniform::{SampleUniform, UniformSampler}; +use rand::prelude::*; use rand::AsByteSliceMut; use BigInt; @@ -9,10 +9,10 @@ use BigUint; use Sign::*; use big_digit::BigDigit; -use bigint::{magnitude, into_magnitude}; +use bigint::{into_magnitude, magnitude}; -use traits::Zero; use integer::Integer; +use traits::Zero; pub trait RandBigInt { /// Generate a random `BigUint` of the given bit size. @@ -110,7 +110,6 @@ impl RandBigInt for R { } } - /// The back-end implementing rand's `UniformSampler` for `BigUint`. #[derive(Clone, Debug)] pub struct UniformBigUint { @@ -151,7 +150,6 @@ impl SampleUniform for BigUint { type Sampler = UniformBigUint; } - /// The back-end implementing rand's `UniformSampler` for `BigInt`. #[derive(Clone, Debug)] pub struct UniformBigInt { diff --git a/src/biguint.rs b/src/biguint.rs index 795ae32..6e715d1 100644 --- a/src/biguint.rs +++ b/src/biguint.rs @@ -1,25 +1,28 @@ -use std::borrow::Cow; -use std::default::Default; -use std::iter::{Product, Sum}; -use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Shl, Shr, Sub, - AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, - MulAssign, RemAssign, ShlAssign, ShrAssign, SubAssign}; -use std::str::{self, FromStr}; -use std::fmt; -use std::cmp; -use std::mem; -use std::cmp::Ordering::{self, Less, Greater, Equal}; -use std::{f32, f64}; -use std::{u8, u64}; #[allow(deprecated, unused_imports)] use std::ascii::AsciiExt; +use std::borrow::Cow; +use std::cmp; +use std::cmp::Ordering::{self, Equal, Greater, Less}; +use std::default::Default; +use std::fmt; +use std::iter::{Product, Sum}; +use std::mem; +use std::ops::{ + Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign, + Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign, +}; +use std::str::{self, FromStr}; +use std::{f32, f64}; +use std::{u64, u8}; #[cfg(feature = "serde")] use serde; use integer::{Integer, Roots}; -use traits::{ToPrimitive, FromPrimitive, Float, Num, Unsigned, CheckedAdd, CheckedSub, CheckedMul, - CheckedDiv, Zero, One, Pow}; +use traits::{ + CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Float, FromPrimitive, Num, One, Pow, + ToPrimitive, Unsigned, Zero, +}; use big_digit::{self, BigDigit, DoubleBigDigit}; @@ -28,10 +31,10 @@ mod algorithms; #[path = "monty.rs"] mod monty; -use self::algorithms::{mac_with_carry, mul3, scalar_mul, div_rem, div_rem_digit}; use self::algorithms::{__add2, __sub2rev, add2, sub2, sub2rev}; use self::algorithms::{biguint_shl, biguint_shr}; use self::algorithms::{cmp_slice, fls, ilog2}; +use self::algorithms::{div_rem, div_rem_digit, mac_with_carry, mul3, scalar_mul}; use self::monty::monty_modpow; use UsizePromotion; @@ -125,11 +128,14 @@ fn from_bitwise_digits_le(v: &[u8], bits: usize) -> BigUint { let digits_per_big_digit = big_digit::BITS / bits; - let data = v.chunks(digits_per_big_digit) - .map(|chunk| { - chunk.iter().rev().fold(0, |acc, &c| (acc << bits) | c as BigDigit) - }) - .collect(); + let data = v + .chunks(digits_per_big_digit) + .map(|chunk| { + chunk + .iter() + .rev() + .fold(0, |acc, &c| (acc << bits) | c as BigDigit) + }).collect(); BigUint::new(data) } @@ -183,11 +189,7 @@ fn from_radix_digits_be(v: &[u8], radix: u32) -> BigUint { let radix = radix as BigDigit; let r = v.len() % power; - let i = if r == 0 { - power - } else { - r - }; + let i = if r == 0 { power } else { r }; let (head, tail) = v.split_at(i); let first = head.iter().fold(0, |acc, &d| acc * radix + d as BigDigit); @@ -441,16 +443,19 @@ macro_rules! pow_impl { #[inline] fn pow(self, mut exp: $T) -> Self::Output { - if exp == 0 { return BigUint::one(); } + if exp == 0 { + return BigUint::one(); + } let mut base = self.clone(); - while exp & 1 == 0 { base = &base * &base; exp >>= 1; } - if exp == 1 { return base; } + if exp == 1 { + return base; + } let mut acc = base.clone(); while exp > 1 { @@ -472,7 +477,7 @@ macro_rules! pow_impl { self.pow(*exp) } } - } + }; } pow_impl!(u8); @@ -1033,7 +1038,9 @@ impl Integer for BigUint { while !m.is_zero() { m >>= twos(&m); - if n > m { mem::swap(&mut n, &mut m) } + if n > m { + mem::swap(&mut n, &mut m) + } m -= &n; } @@ -1085,10 +1092,11 @@ impl Roots for BigUint { assert!(n > 0, "root degree n must be at least 1"); if self.is_zero() || self.is_one() { - return self.clone() + return self.clone(); } - match n { // Optimize for small n + match n { + // Optimize for small n 1 => return self.clone(), 2 => return self.sqrt(), 3 => return self.cbrt(), @@ -1098,7 +1106,7 @@ impl Roots for BigUint { let n = n as usize; let n_min_1 = n - 1; - let guess = BigUint::one() << (self.bits()/n + 1); + let guess = BigUint::one() << (self.bits() / n + 1); let mut u = guess; let mut s: BigUint; @@ -1110,7 +1118,9 @@ impl Roots for BigUint { u = t / n; - if u >= s { break; } + if u >= s { + break; + } } s @@ -1120,10 +1130,10 @@ impl Roots for BigUint { // Brent & Zimmermann, Modern Computer Arithmetic, v0.5.9, Algorithm 1.13 fn sqrt(&self) -> Self { if self.is_zero() || self.is_one() { - return self.clone() + return self.clone(); } - let guess = BigUint::one() << (self.bits()/2 + 1); + let guess = BigUint::one() << (self.bits() / 2 + 1); let mut u = guess; let mut s: BigUint; @@ -1134,7 +1144,9 @@ impl Roots for BigUint { let t: BigUint = &s + q; u = t >> 1; - if u >= s { break; } + if u >= s { + break; + } } s @@ -1142,10 +1154,10 @@ impl Roots for BigUint { fn cbrt(&self) -> Self { if self.is_zero() || self.is_one() { - return self.clone() + return self.clone(); } - let guess = BigUint::one() << (self.bits()/3 + 1); + let guess = BigUint::one() << (self.bits() / 3 + 1); let mut u = guess; let mut s: BigUint; @@ -1156,7 +1168,9 @@ impl Roots for BigUint { let t: BigUint = (&s << 1) + q; u = t / 3u32; - if u >= s { break; } + if u >= s { + break; + } } s @@ -1165,9 +1179,9 @@ impl Roots for BigUint { fn high_bits_to_u64(v: &BigUint) -> u64 { match v.data.len() { - 0 => 0, - 1 => v.data[0] as u64, - _ => { + 0 => 0, + 1 => v.data[0] as u64, + _ => { let mut bits = v.bits(); let mut ret = 0u64; let mut ret_bits = 0; @@ -1179,9 +1193,9 @@ fn high_bits_to_u64(v: &BigUint) -> u64 { if bits_want != 64 { ret <<= bits_want; } - ret |= *d as u64 >> (digit_bits - bits_want); + ret |= *d as u64 >> (digit_bits - bits_want); ret_bits += bits_want; - bits -= bits_want; + bits -= bits_want; if ret_bits == 64 { break; @@ -1375,7 +1389,7 @@ macro_rules! impl_biguint_from_uint { BigUint::from(n as u64) } } - } + }; } impl_biguint_from_uint!(u8); @@ -1404,7 +1418,7 @@ macro_rules! impl_to_biguint { $from_ty(*self) } } - } + }; } impl_to_biguint!(isize, FromPrimitive::from_isize); @@ -1649,7 +1663,9 @@ impl BigUint { /// ``` #[inline] pub fn parse_bytes(buf: &[u8], radix: u32) -> Option { - str::from_utf8(buf).ok().and_then(|s| BigUint::from_str_radix(s, radix).ok()) + str::from_utf8(buf) + .ok() + .and_then(|s| BigUint::from_str_radix(s, radix).ok()) } /// Creates and initializes a `BigUint`. Each u8 of the input slice is @@ -1669,7 +1685,10 @@ impl BigUint { /// assert_eq!(a.to_radix_be(190), inbase190); /// ``` pub fn from_radix_be(buf: &[u8], radix: u32) -> Option { - assert!(2 <= radix && radix <= 256, "The radix must be within 2...256"); + assert!( + 2 <= radix && radix <= 256, + "The radix must be within 2...256" + ); if radix != 256 && buf.iter().any(|&b| b >= radix as u8) { return None; @@ -1709,7 +1728,10 @@ impl BigUint { /// assert_eq!(a.to_radix_be(190), inbase190); /// ``` pub fn from_radix_le(buf: &[u8], radix: u32) -> Option { - assert!(2 <= radix && radix <= 256, "The radix must be within 2...256"); + assert!( + 2 <= radix && radix <= 256, + "The radix must be within 2...256" + ); if radix != 256 && buf.iter().any(|&b| b >= radix as u8) { return None; @@ -1732,7 +1754,6 @@ impl BigUint { Some(res) } - /// Returns the byte representation of the `BigUint` in big-endian byte order. /// /// # Examples @@ -1866,7 +1887,9 @@ impl BigUint { // Otherwise do basically the same as `num::pow`, but with a modulus. let one = BigUint::one(); - if exponent.is_zero() { return one; } + if exponent.is_zero() { + return one; + } let mut base = self % modulus; let mut exp = exponent.clone(); @@ -1874,7 +1897,9 @@ impl BigUint { base = &base * &base % modulus; exp >>= 1; } - if exp == one { return base } + if exp == one { + return base; + } let mut acc = base.clone(); while exp > one { @@ -1953,7 +1978,8 @@ impl IntDigits for BigUint { #[cfg(feature = "serde")] impl serde::Serialize for BigUint { fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer + where + S: serde::Serializer, { // Note: do not change the serialization format, or it may break forward // and backward compatibility of serialized data! If we ever change the @@ -1966,7 +1992,8 @@ impl serde::Serialize for BigUint { #[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for BigUint { fn deserialize(deserializer: D) -> Result - where D: serde::Deserializer<'de> + where + D: serde::Deserializer<'de>, { let data: Vec = try!(Vec::deserialize(deserializer)); Ok(BigUint::new(data)) @@ -1976,7 +2003,10 @@ impl<'de> serde::Deserialize<'de> for BigUint { /// Returns the greatest power of the radix <= big_digit::BASE #[inline] fn get_radix_base(radix: u32) -> (BigDigit, usize) { - debug_assert!(2 <= radix && radix <= 256, "The radix must be within 2...256"); + debug_assert!( + 2 <= radix && radix <= 256, + "The radix must be within 2...256" + ); debug_assert!(!radix.is_power_of_two()); // To generate this table: @@ -2007,539 +2037,538 @@ fn get_radix_base(radix: u32) -> (BigDigit, usize) { // println!("({:20}, {:2}), // {:2}", base, power, radix); // } match big_digit::BITS { - 32 => { + 32 => { const BASES: [(u32, usize); 257] = [ - ( 0, 0), - ( 0, 0), - ( 0, 0), // 2 + (0, 0), + (0, 0), + (0, 0), // 2 (3486784401, 20), // 3 - ( 0, 0), // 4 + (0, 0), // 4 (1220703125, 13), // 5 (2176782336, 12), // 6 (1977326743, 11), // 7 - ( 0, 0), // 8 + (0, 0), // 8 (3486784401, 10), // 9 - (1000000000, 9), // 10 - (2357947691, 9), // 11 - ( 429981696, 8), // 12 - ( 815730721, 8), // 13 - (1475789056, 8), // 14 - (2562890625, 8), // 15 - ( 0, 0), // 16 - ( 410338673, 7), // 17 - ( 612220032, 7), // 18 - ( 893871739, 7), // 19 - (1280000000, 7), // 20 - (1801088541, 7), // 21 - (2494357888, 7), // 22 - (3404825447, 7), // 23 - ( 191102976, 6), // 24 - ( 244140625, 6), // 25 - ( 308915776, 6), // 26 - ( 387420489, 6), // 27 - ( 481890304, 6), // 28 - ( 594823321, 6), // 29 - ( 729000000, 6), // 30 - ( 887503681, 6), // 31 - ( 0, 0), // 32 - (1291467969, 6), // 33 - (1544804416, 6), // 34 - (1838265625, 6), // 35 - (2176782336, 6), // 36 - (2565726409, 6), // 37 - (3010936384, 6), // 38 - (3518743761, 6), // 39 - (4096000000, 6), // 40 - ( 115856201, 5), // 41 - ( 130691232, 5), // 42 - ( 147008443, 5), // 43 - ( 164916224, 5), // 44 - ( 184528125, 5), // 45 - ( 205962976, 5), // 46 - ( 229345007, 5), // 47 - ( 254803968, 5), // 48 - ( 282475249, 5), // 49 - ( 312500000, 5), // 50 - ( 345025251, 5), // 51 - ( 380204032, 5), // 52 - ( 418195493, 5), // 53 - ( 459165024, 5), // 54 - ( 503284375, 5), // 55 - ( 550731776, 5), // 56 - ( 601692057, 5), // 57 - ( 656356768, 5), // 58 - ( 714924299, 5), // 59 - ( 777600000, 5), // 60 - ( 844596301, 5), // 61 - ( 916132832, 5), // 62 - ( 992436543, 5), // 63 - ( 0, 0), // 64 - (1160290625, 5), // 65 - (1252332576, 5), // 66 - (1350125107, 5), // 67 - (1453933568, 5), // 68 - (1564031349, 5), // 69 - (1680700000, 5), // 70 - (1804229351, 5), // 71 - (1934917632, 5), // 72 - (2073071593, 5), // 73 - (2219006624, 5), // 74 - (2373046875, 5), // 75 - (2535525376, 5), // 76 - (2706784157, 5), // 77 - (2887174368, 5), // 78 - (3077056399, 5), // 79 - (3276800000, 5), // 80 - (3486784401, 5), // 81 - (3707398432, 5), // 82 - (3939040643, 5), // 83 - (4182119424, 5), // 84 - ( 52200625, 4), // 85 - ( 54700816, 4), // 86 - ( 57289761, 4), // 87 - ( 59969536, 4), // 88 - ( 62742241, 4), // 89 - ( 65610000, 4), // 90 - ( 68574961, 4), // 91 - ( 71639296, 4), // 92 - ( 74805201, 4), // 93 - ( 78074896, 4), // 94 - ( 81450625, 4), // 95 - ( 84934656, 4), // 96 - ( 88529281, 4), // 97 - ( 92236816, 4), // 98 - ( 96059601, 4), // 99 - ( 100000000, 4), // 100 - ( 104060401, 4), // 101 - ( 108243216, 4), // 102 - ( 112550881, 4), // 103 - ( 116985856, 4), // 104 - ( 121550625, 4), // 105 - ( 126247696, 4), // 106 - ( 131079601, 4), // 107 - ( 136048896, 4), // 108 - ( 141158161, 4), // 109 - ( 146410000, 4), // 110 - ( 151807041, 4), // 111 - ( 157351936, 4), // 112 - ( 163047361, 4), // 113 - ( 168896016, 4), // 114 - ( 174900625, 4), // 115 - ( 181063936, 4), // 116 - ( 187388721, 4), // 117 - ( 193877776, 4), // 118 - ( 200533921, 4), // 119 - ( 207360000, 4), // 120 - ( 214358881, 4), // 121 - ( 221533456, 4), // 122 - ( 228886641, 4), // 123 - ( 236421376, 4), // 124 - ( 244140625, 4), // 125 - ( 252047376, 4), // 126 - ( 260144641, 4), // 127 - ( 0, 0), // 128 - ( 276922881, 4), // 129 - ( 285610000, 4), // 130 - ( 294499921, 4), // 131 - ( 303595776, 4), // 132 - ( 312900721, 4), // 133 - ( 322417936, 4), // 134 - ( 332150625, 4), // 135 - ( 342102016, 4), // 136 - ( 352275361, 4), // 137 - ( 362673936, 4), // 138 - ( 373301041, 4), // 139 - ( 384160000, 4), // 140 - ( 395254161, 4), // 141 - ( 406586896, 4), // 142 - ( 418161601, 4), // 143 - ( 429981696, 4), // 144 - ( 442050625, 4), // 145 - ( 454371856, 4), // 146 - ( 466948881, 4), // 147 - ( 479785216, 4), // 148 - ( 492884401, 4), // 149 - ( 506250000, 4), // 150 - ( 519885601, 4), // 151 - ( 533794816, 4), // 152 - ( 547981281, 4), // 153 - ( 562448656, 4), // 154 - ( 577200625, 4), // 155 - ( 592240896, 4), // 156 - ( 607573201, 4), // 157 - ( 623201296, 4), // 158 - ( 639128961, 4), // 159 - ( 655360000, 4), // 160 - ( 671898241, 4), // 161 - ( 688747536, 4), // 162 - ( 705911761, 4), // 163 - ( 723394816, 4), // 164 - ( 741200625, 4), // 165 - ( 759333136, 4), // 166 - ( 777796321, 4), // 167 - ( 796594176, 4), // 168 - ( 815730721, 4), // 169 - ( 835210000, 4), // 170 - ( 855036081, 4), // 171 - ( 875213056, 4), // 172 - ( 895745041, 4), // 173 - ( 916636176, 4), // 174 - ( 937890625, 4), // 175 - ( 959512576, 4), // 176 - ( 981506241, 4), // 177 - (1003875856, 4), // 178 - (1026625681, 4), // 179 - (1049760000, 4), // 180 - (1073283121, 4), // 181 - (1097199376, 4), // 182 - (1121513121, 4), // 183 - (1146228736, 4), // 184 - (1171350625, 4), // 185 - (1196883216, 4), // 186 - (1222830961, 4), // 187 - (1249198336, 4), // 188 - (1275989841, 4), // 189 - (1303210000, 4), // 190 - (1330863361, 4), // 191 - (1358954496, 4), // 192 - (1387488001, 4), // 193 - (1416468496, 4), // 194 - (1445900625, 4), // 195 - (1475789056, 4), // 196 - (1506138481, 4), // 197 - (1536953616, 4), // 198 - (1568239201, 4), // 199 - (1600000000, 4), // 200 - (1632240801, 4), // 201 - (1664966416, 4), // 202 - (1698181681, 4), // 203 - (1731891456, 4), // 204 - (1766100625, 4), // 205 - (1800814096, 4), // 206 - (1836036801, 4), // 207 - (1871773696, 4), // 208 - (1908029761, 4), // 209 - (1944810000, 4), // 210 - (1982119441, 4), // 211 - (2019963136, 4), // 212 - (2058346161, 4), // 213 - (2097273616, 4), // 214 - (2136750625, 4), // 215 - (2176782336, 4), // 216 - (2217373921, 4), // 217 - (2258530576, 4), // 218 - (2300257521, 4), // 219 - (2342560000, 4), // 220 - (2385443281, 4), // 221 - (2428912656, 4), // 222 - (2472973441, 4), // 223 - (2517630976, 4), // 224 - (2562890625, 4), // 225 - (2608757776, 4), // 226 - (2655237841, 4), // 227 - (2702336256, 4), // 228 - (2750058481, 4), // 229 - (2798410000, 4), // 230 - (2847396321, 4), // 231 - (2897022976, 4), // 232 - (2947295521, 4), // 233 - (2998219536, 4), // 234 - (3049800625, 4), // 235 - (3102044416, 4), // 236 - (3154956561, 4), // 237 - (3208542736, 4), // 238 - (3262808641, 4), // 239 - (3317760000, 4), // 240 - (3373402561, 4), // 241 - (3429742096, 4), // 242 - (3486784401, 4), // 243 - (3544535296, 4), // 244 - (3603000625, 4), // 245 - (3662186256, 4), // 246 - (3722098081, 4), // 247 - (3782742016, 4), // 248 - (3844124001, 4), // 249 - (3906250000, 4), // 250 - (3969126001, 4), // 251 - (4032758016, 4), // 252 - (4097152081, 4), // 253 - (4162314256, 4), // 254 - (4228250625, 4), // 255 - ( 0, 0), // 256 + (1000000000, 9), // 10 + (2357947691, 9), // 11 + (429981696, 8), // 12 + (815730721, 8), // 13 + (1475789056, 8), // 14 + (2562890625, 8), // 15 + (0, 0), // 16 + (410338673, 7), // 17 + (612220032, 7), // 18 + (893871739, 7), // 19 + (1280000000, 7), // 20 + (1801088541, 7), // 21 + (2494357888, 7), // 22 + (3404825447, 7), // 23 + (191102976, 6), // 24 + (244140625, 6), // 25 + (308915776, 6), // 26 + (387420489, 6), // 27 + (481890304, 6), // 28 + (594823321, 6), // 29 + (729000000, 6), // 30 + (887503681, 6), // 31 + (0, 0), // 32 + (1291467969, 6), // 33 + (1544804416, 6), // 34 + (1838265625, 6), // 35 + (2176782336, 6), // 36 + (2565726409, 6), // 37 + (3010936384, 6), // 38 + (3518743761, 6), // 39 + (4096000000, 6), // 40 + (115856201, 5), // 41 + (130691232, 5), // 42 + (147008443, 5), // 43 + (164916224, 5), // 44 + (184528125, 5), // 45 + (205962976, 5), // 46 + (229345007, 5), // 47 + (254803968, 5), // 48 + (282475249, 5), // 49 + (312500000, 5), // 50 + (345025251, 5), // 51 + (380204032, 5), // 52 + (418195493, 5), // 53 + (459165024, 5), // 54 + (503284375, 5), // 55 + (550731776, 5), // 56 + (601692057, 5), // 57 + (656356768, 5), // 58 + (714924299, 5), // 59 + (777600000, 5), // 60 + (844596301, 5), // 61 + (916132832, 5), // 62 + (992436543, 5), // 63 + (0, 0), // 64 + (1160290625, 5), // 65 + (1252332576, 5), // 66 + (1350125107, 5), // 67 + (1453933568, 5), // 68 + (1564031349, 5), // 69 + (1680700000, 5), // 70 + (1804229351, 5), // 71 + (1934917632, 5), // 72 + (2073071593, 5), // 73 + (2219006624, 5), // 74 + (2373046875, 5), // 75 + (2535525376, 5), // 76 + (2706784157, 5), // 77 + (2887174368, 5), // 78 + (3077056399, 5), // 79 + (3276800000, 5), // 80 + (3486784401, 5), // 81 + (3707398432, 5), // 82 + (3939040643, 5), // 83 + (4182119424, 5), // 84 + (52200625, 4), // 85 + (54700816, 4), // 86 + (57289761, 4), // 87 + (59969536, 4), // 88 + (62742241, 4), // 89 + (65610000, 4), // 90 + (68574961, 4), // 91 + (71639296, 4), // 92 + (74805201, 4), // 93 + (78074896, 4), // 94 + (81450625, 4), // 95 + (84934656, 4), // 96 + (88529281, 4), // 97 + (92236816, 4), // 98 + (96059601, 4), // 99 + (100000000, 4), // 100 + (104060401, 4), // 101 + (108243216, 4), // 102 + (112550881, 4), // 103 + (116985856, 4), // 104 + (121550625, 4), // 105 + (126247696, 4), // 106 + (131079601, 4), // 107 + (136048896, 4), // 108 + (141158161, 4), // 109 + (146410000, 4), // 110 + (151807041, 4), // 111 + (157351936, 4), // 112 + (163047361, 4), // 113 + (168896016, 4), // 114 + (174900625, 4), // 115 + (181063936, 4), // 116 + (187388721, 4), // 117 + (193877776, 4), // 118 + (200533921, 4), // 119 + (207360000, 4), // 120 + (214358881, 4), // 121 + (221533456, 4), // 122 + (228886641, 4), // 123 + (236421376, 4), // 124 + (244140625, 4), // 125 + (252047376, 4), // 126 + (260144641, 4), // 127 + (0, 0), // 128 + (276922881, 4), // 129 + (285610000, 4), // 130 + (294499921, 4), // 131 + (303595776, 4), // 132 + (312900721, 4), // 133 + (322417936, 4), // 134 + (332150625, 4), // 135 + (342102016, 4), // 136 + (352275361, 4), // 137 + (362673936, 4), // 138 + (373301041, 4), // 139 + (384160000, 4), // 140 + (395254161, 4), // 141 + (406586896, 4), // 142 + (418161601, 4), // 143 + (429981696, 4), // 144 + (442050625, 4), // 145 + (454371856, 4), // 146 + (466948881, 4), // 147 + (479785216, 4), // 148 + (492884401, 4), // 149 + (506250000, 4), // 150 + (519885601, 4), // 151 + (533794816, 4), // 152 + (547981281, 4), // 153 + (562448656, 4), // 154 + (577200625, 4), // 155 + (592240896, 4), // 156 + (607573201, 4), // 157 + (623201296, 4), // 158 + (639128961, 4), // 159 + (655360000, 4), // 160 + (671898241, 4), // 161 + (688747536, 4), // 162 + (705911761, 4), // 163 + (723394816, 4), // 164 + (741200625, 4), // 165 + (759333136, 4), // 166 + (777796321, 4), // 167 + (796594176, 4), // 168 + (815730721, 4), // 169 + (835210000, 4), // 170 + (855036081, 4), // 171 + (875213056, 4), // 172 + (895745041, 4), // 173 + (916636176, 4), // 174 + (937890625, 4), // 175 + (959512576, 4), // 176 + (981506241, 4), // 177 + (1003875856, 4), // 178 + (1026625681, 4), // 179 + (1049760000, 4), // 180 + (1073283121, 4), // 181 + (1097199376, 4), // 182 + (1121513121, 4), // 183 + (1146228736, 4), // 184 + (1171350625, 4), // 185 + (1196883216, 4), // 186 + (1222830961, 4), // 187 + (1249198336, 4), // 188 + (1275989841, 4), // 189 + (1303210000, 4), // 190 + (1330863361, 4), // 191 + (1358954496, 4), // 192 + (1387488001, 4), // 193 + (1416468496, 4), // 194 + (1445900625, 4), // 195 + (1475789056, 4), // 196 + (1506138481, 4), // 197 + (1536953616, 4), // 198 + (1568239201, 4), // 199 + (1600000000, 4), // 200 + (1632240801, 4), // 201 + (1664966416, 4), // 202 + (1698181681, 4), // 203 + (1731891456, 4), // 204 + (1766100625, 4), // 205 + (1800814096, 4), // 206 + (1836036801, 4), // 207 + (1871773696, 4), // 208 + (1908029761, 4), // 209 + (1944810000, 4), // 210 + (1982119441, 4), // 211 + (2019963136, 4), // 212 + (2058346161, 4), // 213 + (2097273616, 4), // 214 + (2136750625, 4), // 215 + (2176782336, 4), // 216 + (2217373921, 4), // 217 + (2258530576, 4), // 218 + (2300257521, 4), // 219 + (2342560000, 4), // 220 + (2385443281, 4), // 221 + (2428912656, 4), // 222 + (2472973441, 4), // 223 + (2517630976, 4), // 224 + (2562890625, 4), // 225 + (2608757776, 4), // 226 + (2655237841, 4), // 227 + (2702336256, 4), // 228 + (2750058481, 4), // 229 + (2798410000, 4), // 230 + (2847396321, 4), // 231 + (2897022976, 4), // 232 + (2947295521, 4), // 233 + (2998219536, 4), // 234 + (3049800625, 4), // 235 + (3102044416, 4), // 236 + (3154956561, 4), // 237 + (3208542736, 4), // 238 + (3262808641, 4), // 239 + (3317760000, 4), // 240 + (3373402561, 4), // 241 + (3429742096, 4), // 242 + (3486784401, 4), // 243 + (3544535296, 4), // 244 + (3603000625, 4), // 245 + (3662186256, 4), // 246 + (3722098081, 4), // 247 + (3782742016, 4), // 248 + (3844124001, 4), // 249 + (3906250000, 4), // 250 + (3969126001, 4), // 251 + (4032758016, 4), // 252 + (4097152081, 4), // 253 + (4162314256, 4), // 254 + (4228250625, 4), // 255 + (0, 0), // 256 ]; let (base, power) = BASES[radix as usize]; (base as BigDigit, power) } - 64 => { + 64 => { const BASES: [(u64, usize); 257] = [ - ( 0, 0), - ( 0, 0), - ( 9223372036854775808, 63), // 2 + (0, 0), + (0, 0), + (9223372036854775808, 63), // 2 (12157665459056928801, 40), // 3 - ( 4611686018427387904, 31), // 4 - ( 7450580596923828125, 27), // 5 - ( 4738381338321616896, 24), // 6 - ( 3909821048582988049, 22), // 7 - ( 9223372036854775808, 21), // 8 + (4611686018427387904, 31), // 4 + (7450580596923828125, 27), // 5 + (4738381338321616896, 24), // 6 + (3909821048582988049, 22), // 7 + (9223372036854775808, 21), // 8 (12157665459056928801, 20), // 9 (10000000000000000000, 19), // 10 - ( 5559917313492231481, 18), // 11 - ( 2218611106740436992, 17), // 12 - ( 8650415919381337933, 17), // 13 - ( 2177953337809371136, 16), // 14 - ( 6568408355712890625, 16), // 15 - ( 1152921504606846976, 15), // 16 - ( 2862423051509815793, 15), // 17 - ( 6746640616477458432, 15), // 18 + (5559917313492231481, 18), // 11 + (2218611106740436992, 17), // 12 + (8650415919381337933, 17), // 13 + (2177953337809371136, 16), // 14 + (6568408355712890625, 16), // 15 + (1152921504606846976, 15), // 16 + (2862423051509815793, 15), // 17 + (6746640616477458432, 15), // 18 (15181127029874798299, 15), // 19 - ( 1638400000000000000, 14), // 20 - ( 3243919932521508681, 14), // 21 - ( 6221821273427820544, 14), // 22 + (1638400000000000000, 14), // 20 + (3243919932521508681, 14), // 21 + (6221821273427820544, 14), // 22 (11592836324538749809, 14), // 23 - ( 876488338465357824, 13), // 24 - ( 1490116119384765625, 13), // 25 - ( 2481152873203736576, 13), // 26 - ( 4052555153018976267, 13), // 27 - ( 6502111422497947648, 13), // 28 + (876488338465357824, 13), // 24 + (1490116119384765625, 13), // 25 + (2481152873203736576, 13), // 26 + (4052555153018976267, 13), // 27 + (6502111422497947648, 13), // 28 (10260628712958602189, 13), // 29 (15943230000000000000, 13), // 30 - ( 787662783788549761, 12), // 31 - ( 1152921504606846976, 12), // 32 - ( 1667889514952984961, 12), // 33 - ( 2386420683693101056, 12), // 34 - ( 3379220508056640625, 12), // 35 - ( 4738381338321616896, 12), // 36 - ( 6582952005840035281, 12), // 37 - ( 9065737908494995456, 12), // 38 + (787662783788549761, 12), // 31 + (1152921504606846976, 12), // 32 + (1667889514952984961, 12), // 33 + (2386420683693101056, 12), // 34 + (3379220508056640625, 12), // 35 + (4738381338321616896, 12), // 36 + (6582952005840035281, 12), // 37 + (9065737908494995456, 12), // 38 (12381557655576425121, 12), // 39 (16777216000000000000, 12), // 40 - ( 550329031716248441, 11), // 41 - ( 717368321110468608, 11), // 42 - ( 929293739471222707, 11), // 43 - ( 1196683881290399744, 11), // 44 - ( 1532278301220703125, 11), // 45 - ( 1951354384207722496, 11), // 46 - ( 2472159215084012303, 11), // 47 - ( 3116402981210161152, 11), // 48 - ( 3909821048582988049, 11), // 49 - ( 4882812500000000000, 11), // 50 - ( 6071163615208263051, 11), // 51 - ( 7516865509350965248, 11), // 52 - ( 9269035929372191597, 11), // 53 + (550329031716248441, 11), // 41 + (717368321110468608, 11), // 42 + (929293739471222707, 11), // 43 + (1196683881290399744, 11), // 44 + (1532278301220703125, 11), // 45 + (1951354384207722496, 11), // 46 + (2472159215084012303, 11), // 47 + (3116402981210161152, 11), // 48 + (3909821048582988049, 11), // 49 + (4882812500000000000, 11), // 50 + (6071163615208263051, 11), // 51 + (7516865509350965248, 11), // 52 + (9269035929372191597, 11), // 53 (11384956040305711104, 11), // 54 (13931233916552734375, 11), // 55 (16985107389382393856, 11), // 56 - ( 362033331456891249, 10), // 57 - ( 430804206899405824, 10), // 58 - ( 511116753300641401, 10), // 59 - ( 604661760000000000, 10), // 60 - ( 713342911662882601, 10), // 61 - ( 839299365868340224, 10), // 62 - ( 984930291881790849, 10), // 63 - ( 1152921504606846976, 10), // 64 - ( 1346274334462890625, 10), // 65 - ( 1568336880910795776, 10), // 66 - ( 1822837804551761449, 10), // 67 - ( 2113922820157210624, 10), // 68 - ( 2446194060654759801, 10), // 69 - ( 2824752490000000000, 10), // 70 - ( 3255243551009881201, 10), // 71 - ( 3743906242624487424, 10), // 72 - ( 4297625829703557649, 10), // 73 - ( 4923990397355877376, 10), // 74 - ( 5631351470947265625, 10), // 75 - ( 6428888932339941376, 10), // 76 - ( 7326680472586200649, 10), // 77 - ( 8335775831236199424, 10), // 78 - ( 9468276082626847201, 10), // 79 + (362033331456891249, 10), // 57 + (430804206899405824, 10), // 58 + (511116753300641401, 10), // 59 + (604661760000000000, 10), // 60 + (713342911662882601, 10), // 61 + (839299365868340224, 10), // 62 + (984930291881790849, 10), // 63 + (1152921504606846976, 10), // 64 + (1346274334462890625, 10), // 65 + (1568336880910795776, 10), // 66 + (1822837804551761449, 10), // 67 + (2113922820157210624, 10), // 68 + (2446194060654759801, 10), // 69 + (2824752490000000000, 10), // 70 + (3255243551009881201, 10), // 71 + (3743906242624487424, 10), // 72 + (4297625829703557649, 10), // 73 + (4923990397355877376, 10), // 74 + (5631351470947265625, 10), // 75 + (6428888932339941376, 10), // 76 + (7326680472586200649, 10), // 77 + (8335775831236199424, 10), // 78 + (9468276082626847201, 10), // 79 (10737418240000000000, 10), // 80 (12157665459056928801, 10), // 81 (13744803133596058624, 10), // 82 (15516041187205853449, 10), // 83 (17490122876598091776, 10), // 84 - ( 231616946283203125, 9), // 85 - ( 257327417311663616, 9), // 86 - ( 285544154243029527, 9), // 87 - ( 316478381828866048, 9), // 88 - ( 350356403707485209, 9), // 89 - ( 387420489000000000, 9), // 90 - ( 427929800129788411, 9), // 91 - ( 472161363286556672, 9), // 92 - ( 520411082988487293, 9), // 93 - ( 572994802228616704, 9), // 94 - ( 630249409724609375, 9), // 95 - ( 692533995824480256, 9), // 96 - ( 760231058654565217, 9), // 97 - ( 833747762130149888, 9), // 98 - ( 913517247483640899, 9), // 99 - ( 1000000000000000000, 9), // 100 - ( 1093685272684360901, 9), // 101 - ( 1195092568622310912, 9), // 102 - ( 1304773183829244583, 9), // 103 - ( 1423311812421484544, 9), // 104 - ( 1551328215978515625, 9), // 105 - ( 1689478959002692096, 9), // 106 - ( 1838459212420154507, 9), // 107 - ( 1999004627104432128, 9), // 108 - ( 2171893279442309389, 9), // 109 - ( 2357947691000000000, 9), // 110 - ( 2558036924386500591, 9), // 111 - ( 2773078757450186752, 9), // 112 - ( 3004041937984268273, 9), // 113 - ( 3251948521156637184, 9), // 114 - ( 3517876291919921875, 9), // 115 - ( 3802961274698203136, 9), // 116 - ( 4108400332687853397, 9), // 117 - ( 4435453859151328768, 9), // 118 - ( 4785448563124474679, 9), // 119 - ( 5159780352000000000, 9), // 120 - ( 5559917313492231481, 9), // 121 - ( 5987402799531080192, 9), // 122 - ( 6443858614676334363, 9), // 123 - ( 6930988311686938624, 9), // 124 - ( 7450580596923828125, 9), // 125 - ( 8004512848309157376, 9), // 126 - ( 8594754748609397887, 9), // 127 - ( 9223372036854775808, 9), // 128 - ( 9892530380752880769, 9), // 129 - (10604499373000000000, 9), // 130 - (11361656654439817571, 9), // 131 - (12166492167065567232, 9), // 132 - (13021612539908538853, 9), // 133 - (13929745610903012864, 9), // 134 - (14893745087865234375, 9), // 135 - (15916595351771938816, 9), // 136 - (17001416405572203977, 9), // 137 - (18151468971815029248, 9), // 138 - ( 139353667211683681, 8), // 139 - ( 147578905600000000, 8), // 140 - ( 156225851787813921, 8), // 141 - ( 165312903998914816, 8), // 142 - ( 174859124550883201, 8), // 143 - ( 184884258895036416, 8), // 144 - ( 195408755062890625, 8), // 145 - ( 206453783524884736, 8), // 146 - ( 218041257467152161, 8), // 147 - ( 230193853492166656, 8), // 148 - ( 242935032749128801, 8), // 149 - ( 256289062500000000, 8), // 150 - ( 270281038127131201, 8), // 151 - ( 284936905588473856, 8), // 152 - ( 300283484326400961, 8), // 153 - ( 316348490636206336, 8), // 154 - ( 333160561500390625, 8), // 155 - ( 350749278894882816, 8), // 156 - ( 369145194573386401, 8), // 157 - ( 388379855336079616, 8), // 158 - ( 408485828788939521, 8), // 159 - ( 429496729600000000, 8), // 160 - ( 451447246258894081, 8), // 161 - ( 474373168346071296, 8), // 162 - ( 498311414318121121, 8), // 163 - ( 523300059815673856, 8), // 164 - ( 549378366500390625, 8), // 165 - ( 576586811427594496, 8), // 166 - ( 604967116961135041, 8), // 167 - ( 634562281237118976, 8), // 168 - ( 665416609183179841, 8), // 169 - ( 697575744100000000, 8), // 170 - ( 731086699811838561, 8), // 171 - ( 765997893392859136, 8), // 172 - ( 802359178476091681, 8), // 173 - ( 840221879151902976, 8), // 174 - ( 879638824462890625, 8), // 175 - ( 920664383502155776, 8), // 176 - ( 963354501121950081, 8), // 177 - ( 1007766734259732736, 8), // 178 - ( 1053960288888713761, 8), // 179 - ( 1101996057600000000, 8), // 180 - ( 1151936657823500641, 8), // 181 - ( 1203846470694789376, 8), // 182 - ( 1257791680575160641, 8), // 183 - ( 1313840315232157696, 8), // 184 - ( 1372062286687890625, 8), // 185 - ( 1432529432742502656, 8), // 186 - ( 1495315559180183521, 8), // 187 - ( 1560496482665168896, 8), // 188 - ( 1628150074335205281, 8), // 189 - ( 1698356304100000000, 8), // 190 - ( 1771197285652216321, 8), // 191 - ( 1846757322198614016, 8), // 192 - ( 1925122952918976001, 8), // 193 - ( 2006383000160502016, 8), // 194 - ( 2090628617375390625, 8), // 195 - ( 2177953337809371136, 8), // 196 - ( 2268453123948987361, 8), // 197 - ( 2362226417735475456, 8), // 198 - ( 2459374191553118401, 8), // 199 - ( 2560000000000000000, 8), // 200 - ( 2664210032449121601, 8), // 201 - ( 2772113166407885056, 8), // 202 - ( 2883821021683985761, 8), // 203 - ( 2999448015365799936, 8), // 204 - ( 3119111417625390625, 8), // 205 - ( 3242931408352297216, 8), // 206 - ( 3371031134626313601, 8), // 207 - ( 3503536769037500416, 8), // 208 - ( 3640577568861717121, 8), // 209 - ( 3782285936100000000, 8), // 210 - ( 3928797478390152481, 8), // 211 - ( 4080251070798954496, 8), // 212 - ( 4236788918503437921, 8), // 213 - ( 4398556620369715456, 8), // 214 - ( 4565703233437890625, 8), // 215 - ( 4738381338321616896, 8), // 216 - ( 4916747105530914241, 8), // 217 - ( 5100960362726891776, 8), // 218 - ( 5291184662917065441, 8), // 219 - ( 5487587353600000000, 8), // 220 - ( 5690339646868044961, 8), // 221 - ( 5899616690476974336, 8), // 222 - ( 6115597639891380481, 8), // 223 - ( 6338465731314712576, 8), // 224 - ( 6568408355712890625, 8), // 225 - ( 6805617133840466176, 8), // 226 - ( 7050287992278341281, 8), // 227 - ( 7302621240492097536, 8), // 228 - ( 7562821648920027361, 8), // 229 - ( 7831098528100000000, 8), // 230 - ( 8107665808844335041, 8), // 231 - ( 8392742123471896576, 8), // 232 - ( 8686550888106661441, 8), // 233 - ( 8989320386052055296, 8), // 234 - ( 9301283852250390625, 8), // 235 - ( 9622679558836781056, 8), // 236 - ( 9953750901796946721, 8), // 237 - (10294746488738365696, 8), // 238 - (10645920227784266881, 8), // 239 - (11007531417600000000, 8), // 240 - (11379844838561358721, 8), // 241 - (11763130845074473216, 8), // 242 - (12157665459056928801, 8), // 243 - (12563730464589807616, 8), // 244 - (12981613503750390625, 8), // 245 - (13411608173635297536, 8), // 246 - (13854014124583882561, 8), // 247 - (14309137159611744256, 8), // 248 - (14777289335064248001, 8), // 249 - (15258789062500000000, 8), // 250 - (15753961211814252001, 8), // 251 - (16263137215612256256, 8), // 252 - (16786655174842630561, 8), // 253 - (17324859965700833536, 8), // 254 - (17878103347812890625, 8), // 255 - ( 72057594037927936, 7), // 256 + (231616946283203125, 9), // 85 + (257327417311663616, 9), // 86 + (285544154243029527, 9), // 87 + (316478381828866048, 9), // 88 + (350356403707485209, 9), // 89 + (387420489000000000, 9), // 90 + (427929800129788411, 9), // 91 + (472161363286556672, 9), // 92 + (520411082988487293, 9), // 93 + (572994802228616704, 9), // 94 + (630249409724609375, 9), // 95 + (692533995824480256, 9), // 96 + (760231058654565217, 9), // 97 + (833747762130149888, 9), // 98 + (913517247483640899, 9), // 99 + (1000000000000000000, 9), // 100 + (1093685272684360901, 9), // 101 + (1195092568622310912, 9), // 102 + (1304773183829244583, 9), // 103 + (1423311812421484544, 9), // 104 + (1551328215978515625, 9), // 105 + (1689478959002692096, 9), // 106 + (1838459212420154507, 9), // 107 + (1999004627104432128, 9), // 108 + (2171893279442309389, 9), // 109 + (2357947691000000000, 9), // 110 + (2558036924386500591, 9), // 111 + (2773078757450186752, 9), // 112 + (3004041937984268273, 9), // 113 + (3251948521156637184, 9), // 114 + (3517876291919921875, 9), // 115 + (3802961274698203136, 9), // 116 + (4108400332687853397, 9), // 117 + (4435453859151328768, 9), // 118 + (4785448563124474679, 9), // 119 + (5159780352000000000, 9), // 120 + (5559917313492231481, 9), // 121 + (5987402799531080192, 9), // 122 + (6443858614676334363, 9), // 123 + (6930988311686938624, 9), // 124 + (7450580596923828125, 9), // 125 + (8004512848309157376, 9), // 126 + (8594754748609397887, 9), // 127 + (9223372036854775808, 9), // 128 + (9892530380752880769, 9), // 129 + (10604499373000000000, 9), // 130 + (11361656654439817571, 9), // 131 + (12166492167065567232, 9), // 132 + (13021612539908538853, 9), // 133 + (13929745610903012864, 9), // 134 + (14893745087865234375, 9), // 135 + (15916595351771938816, 9), // 136 + (17001416405572203977, 9), // 137 + (18151468971815029248, 9), // 138 + (139353667211683681, 8), // 139 + (147578905600000000, 8), // 140 + (156225851787813921, 8), // 141 + (165312903998914816, 8), // 142 + (174859124550883201, 8), // 143 + (184884258895036416, 8), // 144 + (195408755062890625, 8), // 145 + (206453783524884736, 8), // 146 + (218041257467152161, 8), // 147 + (230193853492166656, 8), // 148 + (242935032749128801, 8), // 149 + (256289062500000000, 8), // 150 + (270281038127131201, 8), // 151 + (284936905588473856, 8), // 152 + (300283484326400961, 8), // 153 + (316348490636206336, 8), // 154 + (333160561500390625, 8), // 155 + (350749278894882816, 8), // 156 + (369145194573386401, 8), // 157 + (388379855336079616, 8), // 158 + (408485828788939521, 8), // 159 + (429496729600000000, 8), // 160 + (451447246258894081, 8), // 161 + (474373168346071296, 8), // 162 + (498311414318121121, 8), // 163 + (523300059815673856, 8), // 164 + (549378366500390625, 8), // 165 + (576586811427594496, 8), // 166 + (604967116961135041, 8), // 167 + (634562281237118976, 8), // 168 + (665416609183179841, 8), // 169 + (697575744100000000, 8), // 170 + (731086699811838561, 8), // 171 + (765997893392859136, 8), // 172 + (802359178476091681, 8), // 173 + (840221879151902976, 8), // 174 + (879638824462890625, 8), // 175 + (920664383502155776, 8), // 176 + (963354501121950081, 8), // 177 + (1007766734259732736, 8), // 178 + (1053960288888713761, 8), // 179 + (1101996057600000000, 8), // 180 + (1151936657823500641, 8), // 181 + (1203846470694789376, 8), // 182 + (1257791680575160641, 8), // 183 + (1313840315232157696, 8), // 184 + (1372062286687890625, 8), // 185 + (1432529432742502656, 8), // 186 + (1495315559180183521, 8), // 187 + (1560496482665168896, 8), // 188 + (1628150074335205281, 8), // 189 + (1698356304100000000, 8), // 190 + (1771197285652216321, 8), // 191 + (1846757322198614016, 8), // 192 + (1925122952918976001, 8), // 193 + (2006383000160502016, 8), // 194 + (2090628617375390625, 8), // 195 + (2177953337809371136, 8), // 196 + (2268453123948987361, 8), // 197 + (2362226417735475456, 8), // 198 + (2459374191553118401, 8), // 199 + (2560000000000000000, 8), // 200 + (2664210032449121601, 8), // 201 + (2772113166407885056, 8), // 202 + (2883821021683985761, 8), // 203 + (2999448015365799936, 8), // 204 + (3119111417625390625, 8), // 205 + (3242931408352297216, 8), // 206 + (3371031134626313601, 8), // 207 + (3503536769037500416, 8), // 208 + (3640577568861717121, 8), // 209 + (3782285936100000000, 8), // 210 + (3928797478390152481, 8), // 211 + (4080251070798954496, 8), // 212 + (4236788918503437921, 8), // 213 + (4398556620369715456, 8), // 214 + (4565703233437890625, 8), // 215 + (4738381338321616896, 8), // 216 + (4916747105530914241, 8), // 217 + (5100960362726891776, 8), // 218 + (5291184662917065441, 8), // 219 + (5487587353600000000, 8), // 220 + (5690339646868044961, 8), // 221 + (5899616690476974336, 8), // 222 + (6115597639891380481, 8), // 223 + (6338465731314712576, 8), // 224 + (6568408355712890625, 8), // 225 + (6805617133840466176, 8), // 226 + (7050287992278341281, 8), // 227 + (7302621240492097536, 8), // 228 + (7562821648920027361, 8), // 229 + (7831098528100000000, 8), // 230 + (8107665808844335041, 8), // 231 + (8392742123471896576, 8), // 232 + (8686550888106661441, 8), // 233 + (8989320386052055296, 8), // 234 + (9301283852250390625, 8), // 235 + (9622679558836781056, 8), // 236 + (9953750901796946721, 8), // 237 + (10294746488738365696, 8), // 238 + (10645920227784266881, 8), // 239 + (11007531417600000000, 8), // 240 + (11379844838561358721, 8), // 241 + (11763130845074473216, 8), // 242 + (12157665459056928801, 8), // 243 + (12563730464589807616, 8), // 244 + (12981613503750390625, 8), // 245 + (13411608173635297536, 8), // 246 + (13854014124583882561, 8), // 247 + (14309137159611744256, 8), // 248 + (14777289335064248001, 8), // 249 + (15258789062500000000, 8), // 250 + (15753961211814252001, 8), // 251 + (16263137215612256256, 8), // 252 + (16786655174842630561, 8), // 253 + (17324859965700833536, 8), // 254 + (17878103347812890625, 8), // 255 + (72057594037927936, 7), // 256 ]; let (base, power) = BASES[radix as usize]; (base as BigDigit, power) } - _ => panic!("Invalid bigdigit size") + _ => panic!("Invalid bigdigit size"), } } - #[test] fn test_from_slice() { fn check(slice: &[BigDigit], data: &[BigDigit]) { diff --git a/src/lib.rs b/src/lib.rs index 992b694..5503bfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,6 @@ //! The `num-bigint` crate is tested for rustc 1.15 and greater. #![doc(html_root_url = "https://docs.rs/num-bigint/0.2")] - // We don't actually support `no_std` yet, and probably won't until `alloc` is stable. We're just // reserving this ability with the "std" feature now, and compilation will fail without. #![cfg_attr(not(feature = "std"), no_std)] @@ -95,8 +94,8 @@ use std::fmt; #[macro_use] mod macros; -mod biguint; mod bigint; +mod biguint; #[cfg(feature = "rand")] mod bigrand; @@ -159,12 +158,12 @@ impl Error for ParseBigIntError { pub use biguint::BigUint; pub use biguint::ToBigUint; -pub use bigint::Sign; pub use bigint::BigInt; +pub use bigint::Sign; pub use bigint::ToBigInt; #[cfg(feature = "rand")] -pub use bigrand::{RandBigInt, RandomBits, UniformBigUint, UniformBigInt}; +pub use bigrand::{RandBigInt, RandomBits, UniformBigInt, UniformBigUint}; mod big_digit { /// A `BigDigit` is a `BigUint`'s composing element. diff --git a/src/macros.rs b/src/macros.rs index 4b4eb5c..fdce3ff 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -12,7 +12,7 @@ macro_rules! forward_val_val_binop { $imp::$method(self, &other) } } - } + }; } macro_rules! forward_val_val_binop_commutative { @@ -30,7 +30,7 @@ macro_rules! forward_val_val_binop_commutative { } } } - } + }; } macro_rules! forward_ref_val_binop { @@ -44,7 +44,7 @@ macro_rules! forward_ref_val_binop { $imp::$method(self, &other) } } - } + }; } macro_rules! forward_ref_val_binop_commutative { @@ -58,7 +58,7 @@ macro_rules! forward_ref_val_binop_commutative { $imp::$method(other, self) } } - } + }; } macro_rules! forward_val_ref_binop { @@ -72,7 +72,7 @@ macro_rules! forward_val_ref_binop { $imp::$method(&self, other) } } - } + }; } macro_rules! forward_ref_ref_binop { @@ -86,7 +86,7 @@ macro_rules! forward_ref_ref_binop { $imp::$method(self.clone(), other) } } - } + }; } macro_rules! forward_ref_ref_binop_commutative { @@ -104,7 +104,7 @@ macro_rules! forward_ref_ref_binop_commutative { } } } - } + }; } macro_rules! forward_val_assign { @@ -115,7 +115,7 @@ macro_rules! forward_val_assign { self.$method(&other); } } - } + }; } macro_rules! forward_val_assign_scalar { (impl $imp:ident for $res:ty, $scalar:ty, $method:ident) => { @@ -125,11 +125,11 @@ macro_rules! forward_val_assign_scalar { self.$method(&other); } } - } + }; } macro_rules! forward_scalar_val_val_binop_commutative { - (impl $imp:ident<$scalar:ty> for $res:ty, $method: ident) => { + (impl $imp:ident < $scalar:ty > for $res:ty, $method:ident) => { impl $imp<$res> for $scalar { type Output = $res; @@ -138,11 +138,11 @@ macro_rules! forward_scalar_val_val_binop_commutative { $imp::$method(other, self) } } - } + }; } macro_rules! forward_scalar_val_ref_binop { - (impl $imp:ident<$scalar:ty> for $res:ty, $method:ident) => { + (impl $imp:ident < $scalar:ty > for $res:ty, $method:ident) => { impl<'a> $imp<&'a $scalar> for $res { type Output = $res; @@ -160,11 +160,11 @@ macro_rules! forward_scalar_val_ref_binop { $imp::$method(*self, other) } } - } + }; } macro_rules! forward_scalar_ref_val_binop { - (impl $imp:ident<$scalar:ty> for $res:ty, $method:ident) => { + (impl $imp:ident < $scalar:ty > for $res:ty, $method:ident) => { impl<'a> $imp<$scalar> for &'a $res { type Output = $res; @@ -182,11 +182,11 @@ macro_rules! forward_scalar_ref_val_binop { $imp::$method(self, other.clone()) } } - } + }; } macro_rules! forward_scalar_ref_ref_binop { - (impl $imp:ident<$scalar:ty> for $res:ty, $method:ident) => { + (impl $imp:ident < $scalar:ty > for $res:ty, $method:ident) => { impl<'a, 'b> $imp<&'b $scalar> for &'a $res { type Output = $res; @@ -204,7 +204,7 @@ macro_rules! forward_scalar_ref_ref_binop { $imp::$method(*self, other.clone()) } } - } + }; } macro_rules! promote_scalars { @@ -333,11 +333,11 @@ macro_rules! impl_sum_iter_type { ($res:ty) => { impl Sum for $res where - $res: Add + $res: Add, { fn sum(iter: I) -> Self where - I: Iterator + I: Iterator, { iter.fold(Zero::zero(), <$res>::add) } @@ -349,11 +349,11 @@ macro_rules! impl_product_iter_type { ($res:ty) => { impl Product for $res where - $res: Mul + $res: Mul, { fn product(iter: I) -> Self where - I: Iterator + I: Iterator, { iter.fold(One::one(), <$res>::mul) } diff --git a/src/monty.rs b/src/monty.rs index 3cf526b..bc3546e 100644 --- a/src/monty.rs +++ b/src/monty.rs @@ -5,7 +5,7 @@ use biguint::BigUint; struct MontyReducer<'a> { n: &'a BigUint, - n0inv: u32 + n0inv: u32, } // Calculate the modular inverse of `num`, using Extended GCD. @@ -33,10 +33,12 @@ fn inv_mod_u32(num: u32) -> u32 { let q = a / b; let r = a % b; // 5: (a, b) <- (b, r) - a = b; b = r; + a = b; + b = r; // 6: (u, w) <- (w, u - qw) - let m = u - w*q; - u = w; w = m; + let m = u - w * q; + u = w; + w = m; } assert!(a == 1); @@ -100,7 +102,7 @@ fn monty_sqr(a: BigUint, mr: &MontyReducer) -> BigUint { monty_redc(&a * &a, mr) } -pub fn monty_modpow(a: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint{ +pub fn monty_modpow(a: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint { let mr = MontyReducer::new(modulus); // Calculate the Montgomery parameter diff --git a/tests/bigint.rs b/tests/bigint.rs index 67c1492..1eb0889 100644 --- a/tests/bigint.rs +++ b/tests/bigint.rs @@ -5,22 +5,22 @@ extern crate num_traits; extern crate rand; use num_bigint::BigUint; -use num_bigint::{BigInt, ToBigInt}; use num_bigint::Sign::{Minus, NoSign, Plus}; +use num_bigint::{BigInt, ToBigInt}; -use std::cmp::Ordering::{Less, Equal, Greater}; -use std::{f32, f64}; -use std::{i8, i16, i32, i64, isize}; +use std::cmp::Ordering::{Equal, Greater, Less}; +use std::collections::hash_map::RandomState; +use std::hash::{BuildHasher, Hash, Hasher}; use std::iter::repeat; -use std::{u8, u16, u32, u64, usize}; +use std::ops::Neg; +use std::{f32, f64}; #[cfg(has_i128)] use std::{i128, u128}; -use std::ops::Neg; -use std::hash::{BuildHasher, Hasher, Hash}; -use std::collections::hash_map::RandomState; +use std::{i16, i32, i64, i8, isize}; +use std::{u16, u32, u64, u8, usize}; use num_integer::Integer; -use num_traits::{Zero, One, Signed, ToPrimitive, FromPrimitive, Num, Float, Pow}; +use num_traits::{Float, FromPrimitive, Num, One, Pow, Signed, ToPrimitive, Zero}; mod consts; use consts::*; @@ -31,8 +31,10 @@ mod macros; #[test] fn test_from_bytes_be() { fn check(s: &str, result: &str) { - assert_eq!(BigInt::from_bytes_be(Plus, s.as_bytes()), - BigInt::parse_bytes(result.as_bytes(), 10).unwrap()); + assert_eq!( + BigInt::from_bytes_be(Plus, s.as_bytes()), + BigInt::parse_bytes(result.as_bytes(), 10).unwrap() + ); } check("A", "65"); check("AA", "16705"); @@ -64,8 +66,10 @@ fn test_to_bytes_be() { #[test] fn test_from_bytes_le() { fn check(s: &str, result: &str) { - assert_eq!(BigInt::from_bytes_le(Plus, s.as_bytes()), - BigInt::parse_bytes(result.as_bytes(), 10).unwrap()); + assert_eq!( + BigInt::from_bytes_le(Plus, s.as_bytes()), + BigInt::parse_bytes(result.as_bytes(), 10).unwrap() + ); } check("A", "65"); check("AA", "16705"); @@ -97,8 +101,12 @@ fn test_to_bytes_le() { #[test] fn test_to_signed_bytes_le() { fn check(s: &str, result: Vec) { - assert_eq!(BigInt::parse_bytes(s.as_bytes(), 10).unwrap().to_signed_bytes_le(), - result); + assert_eq!( + BigInt::parse_bytes(s.as_bytes(), 10) + .unwrap() + .to_signed_bytes_le(), + result + ); } check("0", vec![0]); @@ -113,8 +121,10 @@ fn test_to_signed_bytes_le() { #[test] fn test_from_signed_bytes_le() { fn check(s: &[u8], result: &str) { - assert_eq!(BigInt::from_signed_bytes_le(s), - BigInt::parse_bytes(result.as_bytes(), 10).unwrap()); + assert_eq!( + BigInt::from_signed_bytes_le(s), + BigInt::parse_bytes(result.as_bytes(), 10).unwrap() + ); } check(&[], "0"); @@ -132,8 +142,12 @@ fn test_from_signed_bytes_le() { #[test] fn test_to_signed_bytes_be() { fn check(s: &str, result: Vec) { - assert_eq!(BigInt::parse_bytes(s.as_bytes(), 10).unwrap().to_signed_bytes_be(), - result); + assert_eq!( + BigInt::parse_bytes(s.as_bytes(), 10) + .unwrap() + .to_signed_bytes_be(), + result + ); } check("0", vec![0]); @@ -148,8 +162,10 @@ fn test_to_signed_bytes_be() { #[test] fn test_from_signed_bytes_be() { fn check(s: &[u8], result: &str) { - assert_eq!(BigInt::from_signed_bytes_be(s), - BigInt::parse_bytes(result.as_bytes(), 10).unwrap()); + assert_eq!( + BigInt::from_signed_bytes_be(s), + BigInt::parse_bytes(result.as_bytes(), 10).unwrap() + ); } check(&[], "0"); @@ -361,8 +377,10 @@ fn test_convert_f32() { check(&BigInt::from(u16::MAX), 2.0.powi(16) - 1.0); check(&BigInt::from(1u64 << 32), 2.0.powi(32)); check(&BigInt::from_slice(Plus, &[0, 0, 1]), 2.0.powi(64)); - check(&((BigInt::one() << 100) + (BigInt::one() << 123)), - 2.0.powi(100) + 2.0.powi(123)); + check( + &((BigInt::one() << 100) + (BigInt::one() << 123)), + 2.0.powi(100) + 2.0.powi(123), + ); check(&(BigInt::one() << 127), 2.0.powi(127)); check(&(BigInt::from((1u64 << 24) - 1) << (128 - 24)), f32::MAX); @@ -394,14 +412,18 @@ fn test_convert_f32() { } // rounding - assert_eq!(BigInt::from_f32(-f32::consts::PI), - Some(BigInt::from(-3i32))); + assert_eq!( + BigInt::from_f32(-f32::consts::PI), + Some(BigInt::from(-3i32)) + ); assert_eq!(BigInt::from_f32(-f32::consts::E), Some(BigInt::from(-2i32))); assert_eq!(BigInt::from_f32(-0.99999), Some(BigInt::zero())); assert_eq!(BigInt::from_f32(-0.5), Some(BigInt::zero())); assert_eq!(BigInt::from_f32(-0.0), Some(BigInt::zero())); - assert_eq!(BigInt::from_f32(f32::MIN_POSITIVE / 2.0), - Some(BigInt::zero())); + assert_eq!( + BigInt::from_f32(f32::MIN_POSITIVE / 2.0), + Some(BigInt::zero()) + ); assert_eq!(BigInt::from_f32(f32::MIN_POSITIVE), Some(BigInt::zero())); assert_eq!(BigInt::from_f32(0.5), Some(BigInt::zero())); assert_eq!(BigInt::from_f32(0.99999), Some(BigInt::zero())); @@ -443,8 +465,10 @@ fn test_convert_f64() { check(&BigInt::from(u32::MAX), 2.0.powi(32) - 1.0); check(&BigInt::from(1u64 << 32), 2.0.powi(32)); check(&BigInt::from_slice(Plus, &[0, 0, 1]), 2.0.powi(64)); - check(&((BigInt::one() << 100) + (BigInt::one() << 152)), - 2.0.powi(100) + 2.0.powi(152)); + check( + &((BigInt::one() << 100) + (BigInt::one() << 152)), + 2.0.powi(100) + 2.0.powi(152), + ); check(&(BigInt::one() << 1023), 2.0.powi(1023)); check(&(BigInt::from((1u64 << 53) - 1) << (1024 - 53)), f64::MAX); @@ -468,14 +492,18 @@ fn test_convert_f64() { } // rounding - assert_eq!(BigInt::from_f64(-f64::consts::PI), - Some(BigInt::from(-3i32))); + assert_eq!( + BigInt::from_f64(-f64::consts::PI), + Some(BigInt::from(-3i32)) + ); assert_eq!(BigInt::from_f64(-f64::consts::E), Some(BigInt::from(-2i32))); assert_eq!(BigInt::from_f64(-0.99999), Some(BigInt::zero())); assert_eq!(BigInt::from_f64(-0.5), Some(BigInt::zero())); assert_eq!(BigInt::from_f64(-0.0), Some(BigInt::zero())); - assert_eq!(BigInt::from_f64(f64::MIN_POSITIVE / 2.0), - Some(BigInt::zero())); + assert_eq!( + BigInt::from_f64(f64::MIN_POSITIVE / 2.0), + Some(BigInt::zero()) + ); assert_eq!(BigInt::from_f64(f64::MIN_POSITIVE), Some(BigInt::zero())); assert_eq!(BigInt::from_f64(0.5), Some(BigInt::zero())); assert_eq!(BigInt::from_f64(0.99999), Some(BigInt::zero())); @@ -533,7 +561,10 @@ fn test_convert_from_uint() { check!(u32, BigInt::from_slice(Plus, &[u32::MAX])); check!(u64, BigInt::from_slice(Plus, &[u32::MAX, u32::MAX])); #[cfg(has_i128)] - check!(u128, BigInt::from_slice(Plus, &[u32::MAX, u32::MAX, u32::MAX, u32::MAX])); + check!( + u128, + BigInt::from_slice(Plus, &[u32::MAX, u32::MAX, u32::MAX, u32::MAX]) + ); check!(usize, BigInt::from(usize::MAX as u64)); } @@ -548,36 +579,50 @@ fn test_convert_from_int() { assert_eq!(BigInt::from($ty::one()), BigInt::one()); assert_eq!(BigInt::from($ty::MAX - $ty::one()), $max - BigInt::one()); assert_eq!(BigInt::from($ty::MAX), $max); - } + }; } - check!(i8, - BigInt::from_slice(Minus, &[1 << 7]), - BigInt::from_slice(Plus, &[i8::MAX as u32])); - check!(i16, - BigInt::from_slice(Minus, &[1 << 15]), - BigInt::from_slice(Plus, &[i16::MAX as u32])); - check!(i32, - BigInt::from_slice(Minus, &[1 << 31]), - BigInt::from_slice(Plus, &[i32::MAX as u32])); - check!(i64, - BigInt::from_slice(Minus, &[0, 1 << 31]), - BigInt::from_slice(Plus, &[u32::MAX, i32::MAX as u32])); + check!( + i8, + BigInt::from_slice(Minus, &[1 << 7]), + BigInt::from_slice(Plus, &[i8::MAX as u32]) + ); + check!( + i16, + BigInt::from_slice(Minus, &[1 << 15]), + BigInt::from_slice(Plus, &[i16::MAX as u32]) + ); + check!( + i32, + BigInt::from_slice(Minus, &[1 << 31]), + BigInt::from_slice(Plus, &[i32::MAX as u32]) + ); + check!( + i64, + BigInt::from_slice(Minus, &[0, 1 << 31]), + BigInt::from_slice(Plus, &[u32::MAX, i32::MAX as u32]) + ); #[cfg(has_i128)] - check!(i128, - BigInt::from_slice(Minus, &[0, 0, 0, 1 << 31]), - BigInt::from_slice(Plus, &[u32::MAX, u32::MAX, u32::MAX, i32::MAX as u32])); - check!(isize, - BigInt::from(isize::MIN as i64), - BigInt::from(isize::MAX as i64)); + check!( + i128, + BigInt::from_slice(Minus, &[0, 0, 0, 1 << 31]), + BigInt::from_slice(Plus, &[u32::MAX, u32::MAX, u32::MAX, i32::MAX as u32]) + ); + check!( + isize, + BigInt::from(isize::MIN as i64), + BigInt::from(isize::MAX as i64) + ); } #[test] fn test_convert_from_biguint() { assert_eq!(BigInt::from(BigUint::zero()), BigInt::zero()); assert_eq!(BigInt::from(BigUint::one()), BigInt::one()); - assert_eq!(BigInt::from(BigUint::from_slice(&[1, 2, 3])), - BigInt::from_slice(Plus, &[1, 2, 3])); + assert_eq!( + BigInt::from(BigUint::from_slice(&[1, 2, 3])), + BigInt::from_slice(Plus, &[1, 2, 3]) + ); } #[test] @@ -729,7 +774,6 @@ fn test_div_mod_floor() { } } - #[test] fn test_div_rem() { fn check_sub(a: &BigInt, b: &BigInt, ans_q: &BigInt, ans_r: &BigInt) { @@ -950,7 +994,9 @@ fn test_from_str_radix() { // issue 10522, this hit an edge case that caused it to // attempt to allocate a vector of size (-1u) == huge. - let x: BigInt = format!("1{}", repeat("0").take(36).collect::()).parse().unwrap(); + let x: BigInt = format!("1{}", repeat("0").take(36).collect::()) + .parse() + .unwrap(); let _y = x.to_string(); } @@ -980,8 +1026,10 @@ fn test_binary() { let hello = BigInt::parse_bytes("-224055342307539".as_bytes(), 10).unwrap(); assert_eq!(format!("{:b}", a), "1010"); - assert_eq!(format!("{:b}", hello), - "-110010111100011011110011000101101001100011010011"); + assert_eq!( + format!("{:b}", hello), + "-110010111100011011110011000101101001100011010011" + ); assert_eq!(format!("{:♥>+#8b}", a), "♥+0b1010"); } @@ -1024,8 +1072,8 @@ fn test_negative_shr() { #[test] #[cfg(feature = "rand")] fn test_random_shr() { - use rand::Rng; use rand::distributions::Standard; + use rand::Rng; let mut rng = rand::thread_rng(); for p in rng.sample_iter::(&Standard).take(1000) { @@ -1066,8 +1114,11 @@ fn test_iter_product() { FromPrimitive::from_i32(-1004).unwrap(), FromPrimitive::from_i32(1005).unwrap(), ]; - let result = data.get(0).unwrap() * data.get(1).unwrap() * data.get(2).unwrap() - * data.get(3).unwrap() * data.get(4).unwrap(); + let result = data.get(0).unwrap() + * data.get(1).unwrap() + * data.get(2).unwrap() + * data.get(3).unwrap() + * data.get(4).unwrap(); assert_eq!(result, data.iter().product()); assert_eq!(result, data.into_iter().product()); @@ -1085,8 +1136,10 @@ fn test_iter_sum_generic() { #[test] fn test_iter_product_generic() { let data = vec![1001, -1002, 1003, -1004, 1005]; - let result = data[0].to_bigint().unwrap() * data[1].to_bigint().unwrap() - * data[2].to_bigint().unwrap() * data[3].to_bigint().unwrap() + let result = data[0].to_bigint().unwrap() + * data[1].to_bigint().unwrap() + * data[2].to_bigint().unwrap() + * data[3].to_bigint().unwrap() * data[4].to_bigint().unwrap(); assert_eq!(result, data.iter().product()); @@ -1111,7 +1164,7 @@ fn test_pow() { assert_eq!(minus_two.pow(1 as $t), minus_two, "-2^1"); assert_eq!(minus_two.pow(2 as $t), four, "-2^2"); assert_eq!(minus_two.pow(3 as $t), -&eight, "-2^3"); - } + }; } check!(u8); check!(u16); diff --git a/tests/bigint_bitwise.rs b/tests/bigint_bitwise.rs index db60e98..cc0c493 100644 --- a/tests/bigint_bitwise.rs +++ b/tests/bigint_bitwise.rs @@ -24,41 +24,38 @@ impl ToBigInt for ValueVec { } // a, !a -const NOT_VALUES: &'static [(ValueVec, ValueVec)] - = &[(N, M(&[1])), - (P(&[1]), M(&[2])), - (P(&[2]), M(&[3])), - (P(&[!0 - 2]), M(&[!0 - 1])), - (P(&[!0 - 1]), M(&[!0])), - (P(&[!0]), M(&[0, 1])), - (P(&[0, 1]), M(&[1, 1])), - (P(&[1, 1]), M(&[2, 1]))]; +const NOT_VALUES: &'static [(ValueVec, ValueVec)] = &[ + (N, M(&[1])), + (P(&[1]), M(&[2])), + (P(&[2]), M(&[3])), + (P(&[!0 - 2]), M(&[!0 - 1])), + (P(&[!0 - 1]), M(&[!0])), + (P(&[!0]), M(&[0, 1])), + (P(&[0, 1]), M(&[1, 1])), + (P(&[1, 1]), M(&[2, 1])), +]; // a, b, a & b, a | b, a ^ b -const BITWISE_VALUES: &'static [(ValueVec, ValueVec, ValueVec, ValueVec, ValueVec)] - = &[(N, N, N, N, N), - - (N, P(&[1]), N, P(&[1]), P(&[1])), - (N, P(&[!0]), N, P(&[!0]), P(&[!0])), - (N, P(&[0, 1]), N, P(&[0, 1]), P(&[0, 1])), - - (N, M(&[1]), N, M(&[1]), M(&[1])), - (N, M(&[!0]), N, M(&[!0]), M(&[!0])), - (N, M(&[0, 1]), N, M(&[0, 1]), M(&[0, 1])), - - (P(&[1]), P(&[!0]), P(&[1]), P(&[!0]), P(&[!0 - 1])), - (P(&[!0]), P(&[!0]), P(&[!0]), P(&[!0]), N), - (P(&[!0]), P(&[1, 1]), P(&[1]), P(&[!0, 1]), P(&[!0 - 1, 1])), - - (P(&[1]), M(&[!0]), P(&[1]), M(&[!0]), M(&[0, 1])), - (P(&[!0]), M(&[1]), P(&[!0]), M(&[1]), M(&[0, 1])), - (P(&[!0]), M(&[!0]), P(&[1]), M(&[1]), M(&[2])), - (P(&[!0]), M(&[1, 1]), P(&[!0]), M(&[1, 1]), M(&[0, 2])), - (P(&[1, 1]), M(&[!0]), P(&[1, 1]), M(&[!0]), M(&[0, 2])), - - (M(&[1]), M(&[!0]), M(&[!0]), M(&[1]), P(&[!0 - 1])), - (M(&[!0]), M(&[!0]), M(&[!0]), M(&[!0]), N), - (M(&[!0]), M(&[1, 1]), M(&[!0, 1]), M(&[1]), P(&[!0 - 1, 1]))]; +const BITWISE_VALUES: &'static [(ValueVec, ValueVec, ValueVec, ValueVec, ValueVec)] = &[ + (N, N, N, N, N), + (N, P(&[1]), N, P(&[1]), P(&[1])), + (N, P(&[!0]), N, P(&[!0]), P(&[!0])), + (N, P(&[0, 1]), N, P(&[0, 1]), P(&[0, 1])), + (N, M(&[1]), N, M(&[1]), M(&[1])), + (N, M(&[!0]), N, M(&[!0]), M(&[!0])), + (N, M(&[0, 1]), N, M(&[0, 1]), M(&[0, 1])), + (P(&[1]), P(&[!0]), P(&[1]), P(&[!0]), P(&[!0 - 1])), + (P(&[!0]), P(&[!0]), P(&[!0]), P(&[!0]), N), + (P(&[!0]), P(&[1, 1]), P(&[1]), P(&[!0, 1]), P(&[!0 - 1, 1])), + (P(&[1]), M(&[!0]), P(&[1]), M(&[!0]), M(&[0, 1])), + (P(&[!0]), M(&[1]), P(&[!0]), M(&[1]), M(&[0, 1])), + (P(&[!0]), M(&[!0]), P(&[1]), M(&[1]), M(&[2])), + (P(&[!0]), M(&[1, 1]), P(&[!0]), M(&[1, 1]), M(&[0, 2])), + (P(&[1, 1]), M(&[!0]), P(&[1, 1]), M(&[!0]), M(&[0, 2])), + (M(&[1]), M(&[!0]), M(&[!0]), M(&[1]), P(&[!0 - 1])), + (M(&[!0]), M(&[!0]), M(&[!0]), M(&[!0]), N), + (M(&[!0]), M(&[1, 1]), M(&[!0, 1]), M(&[1]), P(&[!0 - 1, 1])), +]; const I32_MIN: i64 = i32::MIN as i64; const I32_MAX: i64 = i32::MAX as i64; @@ -66,13 +63,50 @@ const U32_MAX: i64 = u32::MAX as i64; // some corner cases const I64_VALUES: &'static [i64] = &[ - i64::MIN, i64::MIN + 1, i64::MIN + 2, i64::MIN + 3, - -U32_MAX - 3, -U32_MAX - 2, -U32_MAX - 1, -U32_MAX, -U32_MAX + 1, -U32_MAX + 2, -U32_MAX + 3, - I32_MIN - 3, I32_MIN - 2, I32_MIN - 1, I32_MIN, I32_MIN + 1, I32_MIN + 2, I32_MIN + 3, - -3, -2, -1, 0, 1, 2, 3, - I32_MAX - 3, I32_MAX - 2, I32_MAX - 1, I32_MAX, I32_MAX + 1, I32_MAX + 2, I32_MAX + 3, - U32_MAX - 3, U32_MAX - 2, U32_MAX - 1, U32_MAX, U32_MAX + 1, U32_MAX + 2, U32_MAX + 3, - i64::MAX - 3, i64::MAX - 2, i64::MAX - 1, i64::MAX]; + i64::MIN, + i64::MIN + 1, + i64::MIN + 2, + i64::MIN + 3, + -U32_MAX - 3, + -U32_MAX - 2, + -U32_MAX - 1, + -U32_MAX, + -U32_MAX + 1, + -U32_MAX + 2, + -U32_MAX + 3, + I32_MIN - 3, + I32_MIN - 2, + I32_MIN - 1, + I32_MIN, + I32_MIN + 1, + I32_MIN + 2, + I32_MIN + 3, + -3, + -2, + -1, + 0, + 1, + 2, + 3, + I32_MAX - 3, + I32_MAX - 2, + I32_MAX - 1, + I32_MAX, + I32_MAX + 1, + I32_MAX + 2, + I32_MAX + 3, + U32_MAX - 3, + U32_MAX - 2, + U32_MAX - 1, + U32_MAX, + U32_MAX + 1, + U32_MAX + 2, + U32_MAX + 3, + i64::MAX - 3, + i64::MAX - 2, + i64::MAX - 1, + i64::MAX, +]; #[test] fn test_not() { diff --git a/tests/bigint_scalar.rs b/tests/bigint_scalar.rs index 4c2fe83..ae9a6d7 100644 --- a/tests/bigint_scalar.rs +++ b/tests/bigint_scalar.rs @@ -3,7 +3,7 @@ extern crate num_traits; use num_bigint::BigInt; use num_bigint::Sign::Plus; -use num_traits::{Zero, Signed, ToPrimitive}; +use num_traits::{Signed, ToPrimitive, Zero}; use std::ops::Neg; @@ -142,5 +142,4 @@ fn test_scalar_div_rem() { check(&a, b, &c, &d); } } - } diff --git a/tests/biguint.rs b/tests/biguint.rs index 35c54c7..09c812f 100644 --- a/tests/biguint.rs +++ b/tests/biguint.rs @@ -2,24 +2,26 @@ extern crate num_bigint; extern crate num_integer; extern crate num_traits; -use num_integer::Integer; -use num_bigint::{BigUint, ToBigUint}; -use num_bigint::{BigInt, ToBigInt}; use num_bigint::Sign::Plus; +use num_bigint::{BigInt, ToBigInt}; +use num_bigint::{BigUint, ToBigUint}; +use num_integer::Integer; -use std::cmp::Ordering::{Less, Equal, Greater}; -use std::{f32, f64}; +use std::cmp::Ordering::{Equal, Greater, Less}; +use std::collections::hash_map::RandomState; +use std::hash::{BuildHasher, Hash, Hasher}; use std::i64; use std::iter::repeat; use std::str::FromStr; -use std::{u8, u16, u32, u64, usize}; +use std::{f32, f64}; #[cfg(has_i128)] use std::{i128, u128}; -use std::hash::{BuildHasher, Hasher, Hash}; -use std::collections::hash_map::RandomState; +use std::{u16, u32, u64, u8, usize}; -use num_traits::{Num, Zero, One, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, ToPrimitive, - FromPrimitive, Float, Pow}; +use num_traits::{ + CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Float, FromPrimitive, Num, One, Pow, + ToPrimitive, Zero, +}; mod consts; use consts::*; @@ -30,8 +32,10 @@ mod macros; #[test] fn test_from_bytes_be() { fn check(s: &str, result: &str) { - assert_eq!(BigUint::from_bytes_be(s.as_bytes()), - BigUint::parse_bytes(result.as_bytes(), 10).unwrap()); + assert_eq!( + BigUint::from_bytes_be(s.as_bytes()), + BigUint::parse_bytes(result.as_bytes(), 10).unwrap() + ); } check("A", "65"); check("AA", "16705"); @@ -61,8 +65,10 @@ fn test_to_bytes_be() { #[test] fn test_from_bytes_le() { fn check(s: &str, result: &str) { - assert_eq!(BigUint::from_bytes_le(s.as_bytes()), - BigUint::parse_bytes(result.as_bytes(), 10).unwrap()); + assert_eq!( + BigUint::from_bytes_le(s.as_bytes()), + BigUint::parse_bytes(result.as_bytes(), 10).unwrap() + ); } check("A", "65"); check("AA", "16705"); @@ -234,115 +240,137 @@ fn test_shl() { check("0", 3, "0"); check("1", 3, "8"); - check("1\ - 0000\ - 0000\ - 0000\ - 0001\ - 0000\ - 0000\ - 0000\ - 0001", - 3, - "8\ - 0000\ - 0000\ - 0000\ - 0008\ - 0000\ - 0000\ - 0000\ - 0008"); - check("1\ - 0000\ - 0001\ - 0000\ - 0001", - 2, - "4\ - 0000\ - 0004\ - 0000\ - 0004"); - check("1\ - 0001\ - 0001", - 1, - "2\ - 0002\ - 0002"); + check( + "1\ + 0000\ + 0000\ + 0000\ + 0001\ + 0000\ + 0000\ + 0000\ + 0001", + 3, + "8\ + 0000\ + 0000\ + 0000\ + 0008\ + 0000\ + 0000\ + 0000\ + 0008", + ); + check( + "1\ + 0000\ + 0001\ + 0000\ + 0001", + 2, + "4\ + 0000\ + 0004\ + 0000\ + 0004", + ); + check( + "1\ + 0001\ + 0001", + 1, + "2\ + 0002\ + 0002", + ); - check("\ - 4000\ - 0000\ - 0000\ - 0000", - 3, - "2\ - 0000\ - 0000\ - 0000\ - 0000"); - check("4000\ - 0000", - 2, - "1\ - 0000\ - 0000"); - check("4000", - 2, - "1\ - 0000"); + check( + "\ + 4000\ + 0000\ + 0000\ + 0000", + 3, + "2\ + 0000\ + 0000\ + 0000\ + 0000", + ); + check( + "4000\ + 0000", + 2, + "1\ + 0000\ + 0000", + ); + check( + "4000", + 2, + "1\ + 0000", + ); - check("4000\ - 0000\ - 0000\ - 0000", - 67, - "2\ - 0000\ - 0000\ - 0000\ - 0000\ - 0000\ - 0000\ - 0000\ - 0000"); - check("4000\ - 0000", - 35, - "2\ - 0000\ - 0000\ - 0000\ - 0000"); - check("4000", - 19, - "2\ - 0000\ - 0000"); + check( + "4000\ + 0000\ + 0000\ + 0000", + 67, + "2\ + 0000\ + 0000\ + 0000\ + 0000\ + 0000\ + 0000\ + 0000\ + 0000", + ); + check( + "4000\ + 0000", + 35, + "2\ + 0000\ + 0000\ + 0000\ + 0000", + ); + check( + "4000", + 19, + "2\ + 0000\ + 0000", + ); - check("fedc\ - ba98\ - 7654\ - 3210\ - fedc\ - ba98\ - 7654\ - 3210", - 4, - "f\ - edcb\ - a987\ - 6543\ - 210f\ - edcb\ - a987\ - 6543\ - 2100"); - check("88887777666655554444333322221111", - 16, - "888877776666555544443333222211110000"); + check( + "fedc\ + ba98\ + 7654\ + 3210\ + fedc\ + ba98\ + 7654\ + 3210", + 4, + "f\ + edcb\ + a987\ + 6543\ + 210f\ + edcb\ + a987\ + 6543\ + 2100", + ); + check( + "88887777666655554444333322221111", + 16, + "888877776666555544443333222211110000", + ); } #[test] @@ -359,111 +387,133 @@ fn test_shr() { check("0", 3, "0"); check("f", 3, "1"); - check("1\ - 0000\ - 0000\ - 0000\ - 0001\ - 0000\ - 0000\ - 0000\ - 0001", - 3, - "2000\ - 0000\ - 0000\ - 0000\ - 2000\ - 0000\ - 0000\ - 0000"); - check("1\ - 0000\ - 0001\ - 0000\ - 0001", - 2, - "4000\ - 0000\ - 4000\ - 0000"); - check("1\ - 0001\ - 0001", - 1, - "8000\ - 8000"); + check( + "1\ + 0000\ + 0000\ + 0000\ + 0001\ + 0000\ + 0000\ + 0000\ + 0001", + 3, + "2000\ + 0000\ + 0000\ + 0000\ + 2000\ + 0000\ + 0000\ + 0000", + ); + check( + "1\ + 0000\ + 0001\ + 0000\ + 0001", + 2, + "4000\ + 0000\ + 4000\ + 0000", + ); + check( + "1\ + 0001\ + 0001", + 1, + "8000\ + 8000", + ); - check("2\ - 0000\ - 0000\ - 0000\ - 0001\ - 0000\ - 0000\ - 0000\ - 0001", - 67, - "4000\ - 0000\ - 0000\ - 0000"); - check("2\ - 0000\ - 0001\ - 0000\ - 0001", - 35, - "4000\ - 0000"); - check("2\ - 0001\ - 0001", - 19, - "4000"); + check( + "2\ + 0000\ + 0000\ + 0000\ + 0001\ + 0000\ + 0000\ + 0000\ + 0001", + 67, + "4000\ + 0000\ + 0000\ + 0000", + ); + check( + "2\ + 0000\ + 0001\ + 0000\ + 0001", + 35, + "4000\ + 0000", + ); + check( + "2\ + 0001\ + 0001", + 19, + "4000", + ); - check("1\ - 0000\ - 0000\ - 0000\ - 0000", - 1, - "8000\ - 0000\ - 0000\ - 0000"); - check("1\ - 0000\ - 0000", - 1, - "8000\ - 0000"); - check("1\ - 0000", - 1, - "8000"); - check("f\ - edcb\ - a987\ - 6543\ - 210f\ - edcb\ - a987\ - 6543\ - 2100", - 4, - "fedc\ - ba98\ - 7654\ - 3210\ - fedc\ - ba98\ - 7654\ - 3210"); + check( + "1\ + 0000\ + 0000\ + 0000\ + 0000", + 1, + "8000\ + 0000\ + 0000\ + 0000", + ); + check( + "1\ + 0000\ + 0000", + 1, + "8000\ + 0000", + ); + check( + "1\ + 0000", + 1, + "8000", + ); + check( + "f\ + edcb\ + a987\ + 6543\ + 210f\ + edcb\ + a987\ + 6543\ + 2100", + 4, + "fedc\ + ba98\ + 7654\ + 3210\ + fedc\ + ba98\ + 7654\ + 3210", + ); - check("888877776666555544443333222211110000", - 16, - "88887777666655554444333322221111"); + check( + "888877776666555544443333222211110000", + 16, + "88887777666655554444333322221111", + ); } // `DoubleBigDigit` size dependent @@ -577,8 +627,10 @@ fn test_convert_f32() { check(&BigUint::from(u16::MAX), 2.0.powi(16) - 1.0); check(&BigUint::from(1u64 << 32), 2.0.powi(32)); check(&BigUint::from_slice(&[0, 0, 1]), 2.0.powi(64)); - check(&((BigUint::one() << 100) + (BigUint::one() << 123)), - 2.0.powi(100) + 2.0.powi(123)); + check( + &((BigUint::one() << 100) + (BigUint::one() << 123)), + 2.0.powi(100) + 2.0.powi(123), + ); check(&(BigUint::one() << 127), 2.0.powi(127)); check(&(BigUint::from((1u64 << 24) - 1) << (128 - 24)), f32::MAX); @@ -611,14 +663,18 @@ fn test_convert_f32() { assert_eq!(BigUint::from_f32(-0.99999), Some(BigUint::zero())); assert_eq!(BigUint::from_f32(-0.5), Some(BigUint::zero())); assert_eq!(BigUint::from_f32(-0.0), Some(BigUint::zero())); - assert_eq!(BigUint::from_f32(f32::MIN_POSITIVE / 2.0), - Some(BigUint::zero())); + assert_eq!( + BigUint::from_f32(f32::MIN_POSITIVE / 2.0), + Some(BigUint::zero()) + ); assert_eq!(BigUint::from_f32(f32::MIN_POSITIVE), Some(BigUint::zero())); assert_eq!(BigUint::from_f32(0.5), Some(BigUint::zero())); assert_eq!(BigUint::from_f32(0.99999), Some(BigUint::zero())); assert_eq!(BigUint::from_f32(f32::consts::E), Some(BigUint::from(2u32))); - assert_eq!(BigUint::from_f32(f32::consts::PI), - Some(BigUint::from(3u32))); + assert_eq!( + BigUint::from_f32(f32::consts::PI), + Some(BigUint::from(3u32)) + ); // special float values assert_eq!(BigUint::from_f32(f32::NAN), None); @@ -648,8 +704,10 @@ fn test_convert_f64() { check(&BigUint::from(u32::MAX), 2.0.powi(32) - 1.0); check(&BigUint::from(1u64 << 32), 2.0.powi(32)); check(&BigUint::from_slice(&[0, 0, 1]), 2.0.powi(64)); - check(&((BigUint::one() << 100) + (BigUint::one() << 152)), - 2.0.powi(100) + 2.0.powi(152)); + check( + &((BigUint::one() << 100) + (BigUint::one() << 152)), + 2.0.powi(100) + 2.0.powi(152), + ); check(&(BigUint::one() << 1023), 2.0.powi(1023)); check(&(BigUint::from((1u64 << 53) - 1) << (1024 - 53)), f64::MAX); @@ -677,14 +735,18 @@ fn test_convert_f64() { assert_eq!(BigUint::from_f64(-0.99999), Some(BigUint::zero())); assert_eq!(BigUint::from_f64(-0.5), Some(BigUint::zero())); assert_eq!(BigUint::from_f64(-0.0), Some(BigUint::zero())); - assert_eq!(BigUint::from_f64(f64::MIN_POSITIVE / 2.0), - Some(BigUint::zero())); + assert_eq!( + BigUint::from_f64(f64::MIN_POSITIVE / 2.0), + Some(BigUint::zero()) + ); assert_eq!(BigUint::from_f64(f64::MIN_POSITIVE), Some(BigUint::zero())); assert_eq!(BigUint::from_f64(0.5), Some(BigUint::zero())); assert_eq!(BigUint::from_f64(0.99999), Some(BigUint::zero())); assert_eq!(BigUint::from_f64(f64::consts::E), Some(BigUint::from(2u32))); - assert_eq!(BigUint::from_f64(f64::consts::PI), - Some(BigUint::from(3u32))); + assert_eq!( + BigUint::from_f64(f64::consts::PI), + Some(BigUint::from(3u32)) + ); // special float values assert_eq!(BigUint::from_f64(f64::NAN), None); @@ -708,8 +770,10 @@ fn test_convert_to_bigint() { assert_eq!(n.to_bigint().unwrap().to_biguint().unwrap(), n); } check(Zero::zero(), Zero::zero()); - check(BigUint::new(vec![1, 2, 3]), - BigInt::from_biguint(Plus, BigUint::new(vec![1, 2, 3]))); + check( + BigUint::new(vec![1, 2, 3]), + BigInt::from_biguint(Plus, BigUint::new(vec![1, 2, 3])), + ); } #[test] @@ -720,7 +784,7 @@ fn test_convert_from_uint() { assert_eq!(BigUint::from($ty::one()), BigUint::one()); assert_eq!(BigUint::from($ty::MAX - $ty::one()), $max - BigUint::one()); assert_eq!(BigUint::from($ty::MAX), $max); - } + }; } check!(u8, BigUint::from_slice(&[u8::MAX as u32])); @@ -728,7 +792,10 @@ fn test_convert_from_uint() { check!(u32, BigUint::from_slice(&[u32::MAX])); check!(u64, BigUint::from_slice(&[u32::MAX, u32::MAX])); #[cfg(has_i128)] - check!(u128, BigUint::from_slice(&[u32::MAX, u32::MAX, u32::MAX, u32::MAX])); + check!( + u128, + BigUint::from_slice(&[u32::MAX, u32::MAX, u32::MAX, u32::MAX]) + ); check!(usize, BigUint::from(usize::MAX as u64)); } @@ -974,69 +1041,113 @@ fn test_is_even() { fn to_str_pairs() -> Vec<(BigUint, Vec<(u32, String)>)> { let bits = 32; - vec![(Zero::zero(), - vec![(2, "0".to_string()), (3, "0".to_string())]), - (BigUint::from_slice(&[0xff]), - vec![(2, "11111111".to_string()), - (3, "100110".to_string()), - (4, "3333".to_string()), - (5, "2010".to_string()), - (6, "1103".to_string()), - (7, "513".to_string()), - (8, "377".to_string()), - (9, "313".to_string()), - (10, "255".to_string()), - (11, "212".to_string()), - (12, "193".to_string()), - (13, "168".to_string()), - (14, "143".to_string()), - (15, "120".to_string()), - (16, "ff".to_string())]), - (BigUint::from_slice(&[0xfff]), - vec![(2, "111111111111".to_string()), - (4, "333333".to_string()), - (16, "fff".to_string())]), - (BigUint::from_slice(&[1, 2]), - vec![(2, - format!("10{}1", repeat("0").take(bits - 1).collect::())), - (4, - format!("2{}1", repeat("0").take(bits / 2 - 1).collect::())), - (10, - match bits { - 64 => "36893488147419103233".to_string(), - 32 => "8589934593".to_string(), - 16 => "131073".to_string(), - _ => panic!(), - }), - (16, - format!("2{}1", repeat("0").take(bits / 4 - 1).collect::()))]), - (BigUint::from_slice(&[1, 2, 3]), - vec![(2, - format!("11{}10{}1", + vec![ + ( + Zero::zero(), + vec![(2, "0".to_string()), (3, "0".to_string())], + ), + ( + BigUint::from_slice(&[0xff]), + vec![ + (2, "11111111".to_string()), + (3, "100110".to_string()), + (4, "3333".to_string()), + (5, "2010".to_string()), + (6, "1103".to_string()), + (7, "513".to_string()), + (8, "377".to_string()), + (9, "313".to_string()), + (10, "255".to_string()), + (11, "212".to_string()), + (12, "193".to_string()), + (13, "168".to_string()), + (14, "143".to_string()), + (15, "120".to_string()), + (16, "ff".to_string()), + ], + ), + ( + BigUint::from_slice(&[0xfff]), + vec![ + (2, "111111111111".to_string()), + (4, "333333".to_string()), + (16, "fff".to_string()), + ], + ), + ( + BigUint::from_slice(&[1, 2]), + vec![ + ( + 2, + format!("10{}1", repeat("0").take(bits - 1).collect::()), + ), + ( + 4, + format!("2{}1", repeat("0").take(bits / 2 - 1).collect::()), + ), + ( + 10, + match bits { + 64 => "36893488147419103233".to_string(), + 32 => "8589934593".to_string(), + 16 => "131073".to_string(), + _ => panic!(), + }, + ), + ( + 16, + format!("2{}1", repeat("0").take(bits / 4 - 1).collect::()), + ), + ], + ), + ( + BigUint::from_slice(&[1, 2, 3]), + vec![ + ( + 2, + format!( + "11{}10{}1", repeat("0").take(bits - 2).collect::(), - repeat("0").take(bits - 1).collect::())), - (4, - format!("3{}2{}1", + repeat("0").take(bits - 1).collect::() + ), + ), + ( + 4, + format!( + "3{}2{}1", repeat("0").take(bits / 2 - 1).collect::(), - repeat("0").take(bits / 2 - 1).collect::())), - (8, - match bits { - 64 => "14000000000000000000004000000000000000000001".to_string(), - 32 => "6000000000100000000001".to_string(), - 16 => "140000400001".to_string(), - _ => panic!(), - }), - (10, - match bits { - 64 => "1020847100762815390427017310442723737601".to_string(), - 32 => "55340232229718589441".to_string(), - 16 => "12885032961".to_string(), - _ => panic!(), - }), - (16, - format!("3{}2{}1", + repeat("0").take(bits / 2 - 1).collect::() + ), + ), + ( + 8, + match bits { + 64 => "14000000000000000000004000000000000000000001".to_string(), + 32 => "6000000000100000000001".to_string(), + 16 => "140000400001".to_string(), + _ => panic!(), + }, + ), + ( + 10, + match bits { + 64 => "1020847100762815390427017310442723737601".to_string(), + 32 => "55340232229718589441".to_string(), + 16 => "12885032961".to_string(), + _ => panic!(), + }, + ), + ( + 16, + format!( + "3{}2{}1", repeat("0").take(bits / 4 - 1).collect::(), - repeat("0").take(bits / 4 - 1).collect::()))])] + repeat("0").take(bits / 4 - 1).collect::() + ), + ), + ], + ), + ] } #[test] @@ -1053,20 +1164,48 @@ fn test_to_str_radix() { #[test] fn test_from_and_to_radix() { - const GROUND_TRUTH : &'static[(&'static[u8], u32, &'static[u8])] = &[ - (b"0", 42, &[0]), - (b"ffffeeffbb", 2, &[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), - (b"ffffeeffbb", 3, &[2, 2, 1, 1, 2, 1, 1, 2, 0, 0, 0, 0, 0, 1, 2, - 0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 1]), - (b"ffffeeffbb", 4, &[3, 2, 3, 2, 3, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, - 3, 3, 3, 3, 3]), - (b"ffffeeffbb", 5, &[0, 4, 3, 3, 1, 4, 2, 4, 1, 4, 4, 2, 3, 0, 0, - 1, 2, 1]), - (b"ffffeeffbb", 6, &[5, 5, 4, 5, 5, 0, 0, 1, 2, 5, 3, 0, 1, 0, 2, 2]), - (b"ffffeeffbb", 7, &[4, 2, 3, 6, 0, 1, 6, 1, 6, 2, 0, 3, 2, 4, 1]), - (b"ffffeeffbb", 8, &[3, 7, 6, 7, 7, 5, 3, 7, 7, 7, 7, 7, 7, 1]), + const GROUND_TRUTH: &'static [(&'static [u8], u32, &'static [u8])] = &[ + (b"0", 42, &[0]), + ( + b"ffffeeffbb", + 2, + &[ + 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + ], + ), + ( + b"ffffeeffbb", + 3, + &[ + 2, 2, 1, 1, 2, 1, 1, 2, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 1, + ], + ), + ( + b"ffffeeffbb", + 4, + &[3, 2, 3, 2, 3, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3], + ), + ( + b"ffffeeffbb", + 5, + &[0, 4, 3, 3, 1, 4, 2, 4, 1, 4, 4, 2, 3, 0, 0, 1, 2, 1], + ), + ( + b"ffffeeffbb", + 6, + &[5, 5, 4, 5, 5, 0, 0, 1, 2, 5, 3, 0, 1, 0, 2, 2], + ), + ( + b"ffffeeffbb", + 7, + &[4, 2, 3, 6, 0, 1, 6, 1, 6, 2, 0, 3, 2, 4, 1], + ), + ( + b"ffffeeffbb", + 8, + &[3, 7, 6, 7, 7, 5, 3, 7, 7, 7, 7, 7, 7, 1], + ), (b"ffffeeffbb", 9, &[8, 4, 5, 7, 0, 0, 3, 2, 0, 3, 0, 8, 3]), (b"ffffeeffbb", 10, &[5, 9, 5, 3, 1, 5, 0, 1, 5, 9, 9, 0, 1]), (b"ffffeeffbb", 11, &[10, 7, 6, 5, 2, 0, 3, 3, 3, 4, 9, 3]), @@ -1326,14 +1465,20 @@ fn test_from_and_to_radix() { inbase_be.reverse(); // now le assert_eq!(inbase_be, inbaseradix_le); // from_radix_le - assert_eq!(BigUint::from_radix_le(inbaseradix_le, radix).unwrap(), bigint); + assert_eq!( + BigUint::from_radix_le(inbaseradix_le, radix).unwrap(), + bigint + ); // from_radix_be let mut inbaseradix_be = Vec::from(inbaseradix_le); inbaseradix_be.reverse(); - assert_eq!(BigUint::from_radix_be(&inbaseradix_be, radix).unwrap(), bigint); + assert_eq!( + BigUint::from_radix_be(&inbaseradix_be, radix).unwrap(), + bigint + ); } - assert!(BigUint::from_radix_le(&[10,100,10], 50).is_none()); + assert!(BigUint::from_radix_le(&[10, 100, 10], 50).is_none()); } #[test] @@ -1410,8 +1555,10 @@ fn test_binary() { let hello = BigUint::parse_bytes("224055342307539".as_bytes(), 10).unwrap(); assert_eq!(format!("{:b}", a), "1010"); - assert_eq!(format!("{:b}", hello), - "110010111100011011110011000101101001100011010011"); + assert_eq!( + format!("{:b}", hello), + "110010111100011011110011000101101001100011010011" + ); assert_eq!(format!("{:♥>+#8b}", a), "♥+0b1010"); } @@ -1504,8 +1651,11 @@ fn test_iter_product() { FromPrimitive::from_u32(1004).unwrap(), FromPrimitive::from_u32(1005).unwrap(), ]; - let result = data.get(0).unwrap() * data.get(1).unwrap() * data.get(2).unwrap() - * data.get(3).unwrap() * data.get(4).unwrap(); + let result = data.get(0).unwrap() + * data.get(1).unwrap() + * data.get(2).unwrap() + * data.get(3).unwrap() + * data.get(4).unwrap(); assert_eq!(result, data.iter().product()); assert_eq!(result, data.into_iter().product()); @@ -1523,8 +1673,10 @@ fn test_iter_sum_generic() { #[test] fn test_iter_product_generic() { let data = vec![1001_u32, 1002, 1003, 1004, 1005]; - let result = data[0].to_biguint().unwrap() * data[1].to_biguint().unwrap() - * data[2].to_biguint().unwrap() * data[3].to_biguint().unwrap() + let result = data[0].to_biguint().unwrap() + * data[1].to_biguint().unwrap() + * data[2].to_biguint().unwrap() + * data[3].to_biguint().unwrap() * data[4].to_biguint().unwrap(); assert_eq!(result, data.iter().product()); @@ -1548,7 +1700,7 @@ fn test_pow() { assert_eq!(two.pow(10 as $t), tentwentyfour); assert_eq!(two.pow(11 as $t), twentyfourtyeight); assert_eq!(two.pow(&(11 as $t)), twentyfourtyeight); - } + }; } check!(u8); check!(u16); diff --git a/tests/biguint_scalar.rs b/tests/biguint_scalar.rs index 28461b6..04799ee 100644 --- a/tests/biguint_scalar.rs +++ b/tests/biguint_scalar.rs @@ -2,7 +2,7 @@ extern crate num_bigint; extern crate num_traits; use num_bigint::BigUint; -use num_traits::{Zero, ToPrimitive}; +use num_traits::{ToPrimitive, Zero}; mod consts; use consts::*; diff --git a/tests/consts/mod.rs b/tests/consts/mod.rs index 8b9653a..df22a68 100644 --- a/tests/consts/mod.rs +++ b/tests/consts/mod.rs @@ -3,11 +3,7 @@ pub const N1: u32 = -1i32 as u32; pub const N2: u32 = -2i32 as u32; -pub const SUM_TRIPLES: &'static [( - &'static [u32], - &'static [u32], - &'static [u32], -)] = &[ +pub const SUM_TRIPLES: &'static [(&'static [u32], &'static [u32], &'static [u32])] = &[ (&[], &[], &[]), (&[], &[1], &[1]), (&[1], &[1], &[2]), @@ -20,11 +16,7 @@ pub const SUM_TRIPLES: &'static [( ]; pub const M: u32 = ::std::u32::MAX; -pub const MUL_TRIPLES: &'static [( - &'static [u32], - &'static [u32], - &'static [u32], -)] = &[ +pub const MUL_TRIPLES: &'static [(&'static [u32], &'static [u32], &'static [u32])] = &[ (&[], &[], &[]), (&[], &[1], &[]), (&[2], &[], &[]), diff --git a/tests/macros/mod.rs b/tests/macros/mod.rs index 9b4391d..90606ec 100644 --- a/tests/macros/mod.rs +++ b/tests/macros/mod.rs @@ -12,15 +12,13 @@ macro_rules! assert_op { /// Assert that an assign-op works for all val/ref combinations macro_rules! assert_assign_op { - ($left:ident $op:tt $right:ident == $expected:expr) => { - { - let mut left = $left.clone(); - assert_eq!({ left $op &$right; left}, $expected); + ($left:ident $op:tt $right:ident == $expected:expr) => {{ + let mut left = $left.clone(); + assert_eq!({ left $op &$right; left}, $expected); - let mut left = $left.clone(); - assert_eq!({ left $op $right.clone(); left}, $expected); - } - }; + let mut left = $left.clone(); + assert_eq!({ left $op $right.clone(); left}, $expected); + }}; } /// Assert that an op works for scalar left or right diff --git a/tests/modpow.rs b/tests/modpow.rs index 0390976..b7a992c 100644 --- a/tests/modpow.rs +++ b/tests/modpow.rs @@ -3,58 +3,58 @@ extern crate num_integer; extern crate num_traits; static BIG_B: &'static str = "\ - efac3c0a_0de55551_fee0bfe4_67fa017a_1a898fa1_6ca57cb1\ - ca9e3248_cacc09a9_b99d6abc_38418d0f_82ae4238_d9a68832\ - aadec7c1_ac5fed48_7a56a71b_67ac59d5_afb28022_20d9592d\ - 247c4efc_abbd9b75_586088ee_1dc00dc4_232a8e15_6e8191dd\ - 675b6ae0_c80f5164_752940bc_284b7cee_885c1e10_e495345b\ - 8fbe9cfd_e5233fe1_19459d0b_d64be53c_27de5a02_a829976b\ - 33096862_82dad291_bd38b6a9_be396646_ddaf8039_a2573c39\ - 1b14e8bc_2cb53e48_298c047e_d9879e9c_5a521076_f0e27df3\ - 990e1659_d3d8205b_6443ebc0_9918ebee_6764f668_9f2b2be3\ - b59cbc76_d76d0dfc_d737c3ec_0ccf9c00_ad0554bf_17e776ad\ - b4edf9cc_6ce540be_76229093_5c53893b"; + efac3c0a_0de55551_fee0bfe4_67fa017a_1a898fa1_6ca57cb1\ + ca9e3248_cacc09a9_b99d6abc_38418d0f_82ae4238_d9a68832\ + aadec7c1_ac5fed48_7a56a71b_67ac59d5_afb28022_20d9592d\ + 247c4efc_abbd9b75_586088ee_1dc00dc4_232a8e15_6e8191dd\ + 675b6ae0_c80f5164_752940bc_284b7cee_885c1e10_e495345b\ + 8fbe9cfd_e5233fe1_19459d0b_d64be53c_27de5a02_a829976b\ + 33096862_82dad291_bd38b6a9_be396646_ddaf8039_a2573c39\ + 1b14e8bc_2cb53e48_298c047e_d9879e9c_5a521076_f0e27df3\ + 990e1659_d3d8205b_6443ebc0_9918ebee_6764f668_9f2b2be3\ + b59cbc76_d76d0dfc_d737c3ec_0ccf9c00_ad0554bf_17e776ad\ + b4edf9cc_6ce540be_76229093_5c53893b"; static BIG_E: &'static str = "\ - be0e6ea6_08746133_e0fbc1bf_82dba91e_e2b56231_a81888d2\ - a833a1fc_f7ff002a_3c486a13_4f420bf3_a5435be9_1a5c8391\ - 774d6e6c_085d8357_b0c97d4d_2bb33f7c_34c68059_f78d2541\ - eacc8832_426f1816_d3be001e_b69f9242_51c7708e_e10efe98\ - 449c9a4a_b55a0f23_9d797410_515da00d_3ea07970_4478a2ca\ - c3d5043c_bd9be1b4_6dce479d_4302d344_84a939e6_0ab5ada7\ - 12ae34b2_30cc473c_9f8ee69d_2cac5970_29f5bf18_bc8203e4\ - f3e895a2_13c94f1e_24c73d77_e517e801_53661fdd_a2ce9e47\ - a73dd7f8_2f2adb1e_3f136bf7_8ae5f3b8_08730de1_a4eff678\ - e77a06d0_19a522eb_cbefba2a_9caf7736_b157c5c6_2d192591\ - 17946850_2ddb1822_117b68a0_32f7db88"; + be0e6ea6_08746133_e0fbc1bf_82dba91e_e2b56231_a81888d2\ + a833a1fc_f7ff002a_3c486a13_4f420bf3_a5435be9_1a5c8391\ + 774d6e6c_085d8357_b0c97d4d_2bb33f7c_34c68059_f78d2541\ + eacc8832_426f1816_d3be001e_b69f9242_51c7708e_e10efe98\ + 449c9a4a_b55a0f23_9d797410_515da00d_3ea07970_4478a2ca\ + c3d5043c_bd9be1b4_6dce479d_4302d344_84a939e6_0ab5ada7\ + 12ae34b2_30cc473c_9f8ee69d_2cac5970_29f5bf18_bc8203e4\ + f3e895a2_13c94f1e_24c73d77_e517e801_53661fdd_a2ce9e47\ + a73dd7f8_2f2adb1e_3f136bf7_8ae5f3b8_08730de1_a4eff678\ + e77a06d0_19a522eb_cbefba2a_9caf7736_b157c5c6_2d192591\ + 17946850_2ddb1822_117b68a0_32f7db88"; // This modulus is the prime from the 2048-bit MODP DH group: // https://tools.ietf.org/html/rfc3526#section-3 static BIG_M: &'static str = "\ - FFFFFFFF_FFFFFFFF_C90FDAA2_2168C234_C4C6628B_80DC1CD1\ - 29024E08_8A67CC74_020BBEA6_3B139B22_514A0879_8E3404DD\ - EF9519B3_CD3A431B_302B0A6D_F25F1437_4FE1356D_6D51C245\ - E485B576_625E7EC6_F44C42E9_A637ED6B_0BFF5CB6_F406B7ED\ - EE386BFB_5A899FA5_AE9F2411_7C4B1FE6_49286651_ECE45B3D\ - C2007CB8_A163BF05_98DA4836_1C55D39A_69163FA8_FD24CF5F\ - 83655D23_DCA3AD96_1C62F356_208552BB_9ED52907_7096966D\ - 670C354E_4ABC9804_F1746C08_CA18217C_32905E46_2E36CE3B\ - E39E772C_180E8603_9B2783A2_EC07A28F_B5C55DF0_6F4C52C9\ - DE2BCBF6_95581718_3995497C_EA956AE5_15D22618_98FA0510\ - 15728E5A_8AACAA68_FFFFFFFF_FFFFFFFF"; + FFFFFFFF_FFFFFFFF_C90FDAA2_2168C234_C4C6628B_80DC1CD1\ + 29024E08_8A67CC74_020BBEA6_3B139B22_514A0879_8E3404DD\ + EF9519B3_CD3A431B_302B0A6D_F25F1437_4FE1356D_6D51C245\ + E485B576_625E7EC6_F44C42E9_A637ED6B_0BFF5CB6_F406B7ED\ + EE386BFB_5A899FA5_AE9F2411_7C4B1FE6_49286651_ECE45B3D\ + C2007CB8_A163BF05_98DA4836_1C55D39A_69163FA8_FD24CF5F\ + 83655D23_DCA3AD96_1C62F356_208552BB_9ED52907_7096966D\ + 670C354E_4ABC9804_F1746C08_CA18217C_32905E46_2E36CE3B\ + E39E772C_180E8603_9B2783A2_EC07A28F_B5C55DF0_6F4C52C9\ + DE2BCBF6_95581718_3995497C_EA956AE5_15D22618_98FA0510\ + 15728E5A_8AACAA68_FFFFFFFF_FFFFFFFF"; static BIG_R: &'static str = "\ - a1468311_6e56edc9_7a98228b_5e924776_0dd7836e_caabac13\ - eda5373b_4752aa65_a1454850_40dc770e_30aa8675_6be7d3a8\ - 9d3085e4_da5155cf_b451ef62_54d0da61_cf2b2c87_f495e096\ - 055309f7_77802bbb_37271ba8_1313f1b5_075c75d1_024b6c77\ - fdb56f17_b05bce61_e527ebfd_2ee86860_e9907066_edd526e7\ - 93d289bf_6726b293_41b0de24_eff82424_8dfd374b_4ec59542\ - 35ced2b2_6b195c90_10042ffb_8f58ce21_bc10ec42_64fda779\ - d352d234_3d4eaea6_a86111ad_a37e9555_43ca78ce_2885bed7\ - 5a30d182_f1cf6834_dc5b6e27_1a41ac34_a2e91e11_33363ff0\ - f88a7b04_900227c9_f6e6d06b_7856b4bb_4e354d61_060db6c8\ - 109c4735_6e7db425_7b5d74c7_0b709508"; + a1468311_6e56edc9_7a98228b_5e924776_0dd7836e_caabac13\ + eda5373b_4752aa65_a1454850_40dc770e_30aa8675_6be7d3a8\ + 9d3085e4_da5155cf_b451ef62_54d0da61_cf2b2c87_f495e096\ + 055309f7_77802bbb_37271ba8_1313f1b5_075c75d1_024b6c77\ + fdb56f17_b05bce61_e527ebfd_2ee86860_e9907066_edd526e7\ + 93d289bf_6726b293_41b0de24_eff82424_8dfd374b_4ec59542\ + 35ced2b2_6b195c90_10042ffb_8f58ce21_bc10ec42_64fda779\ + d352d234_3d4eaea6_a86111ad_a37e9555_43ca78ce_2885bed7\ + 5a30d182_f1cf6834_dc5b6e27_1a41ac34_a2e91e11_33363ff0\ + f88a7b04_900227c9_f6e6d06b_7856b4bb_4e354d61_060db6c8\ + 109c4735_6e7db425_7b5d74c7_0b709508"; mod biguint { use num_bigint::BigUint; @@ -102,7 +102,7 @@ mod biguint { mod bigint { use num_bigint::BigInt; use num_integer::Integer; - use num_traits::{Num, Zero, One, Signed}; + use num_traits::{Num, One, Signed, Zero}; fn check_modpow>(b: T, e: T, m: T, r: T) { fn check(b: &BigInt, e: &BigInt, m: &BigInt, r: &BigInt) { diff --git a/tests/rand.rs b/tests/rand.rs index fcbb8f6..666b764 100644 --- a/tests/rand.rs +++ b/tests/rand.rs @@ -7,9 +7,9 @@ extern crate rand; mod biguint { use num_bigint::{BigUint, RandBigInt, RandomBits}; use num_traits::Zero; + use rand::distributions::Uniform; use rand::thread_rng; use rand::{Rng, SeedableRng}; - use rand::distributions::Uniform; #[test] fn test_rand() { @@ -164,9 +164,9 @@ mod biguint { mod bigint { use num_bigint::{BigInt, RandBigInt, RandomBits}; use num_traits::Zero; + use rand::distributions::Uniform; use rand::thread_rng; use rand::{Rng, SeedableRng}; - use rand::distributions::Uniform; #[test] fn test_rand() { diff --git a/tests/roots.rs b/tests/roots.rs index 442f40a..9c4ee48 100644 --- a/tests/roots.rs +++ b/tests/roots.rs @@ -58,7 +58,7 @@ mod biguint { mod bigint { use num_bigint::BigInt; - use num_traits::{Signed, Pow}; + use num_traits::{Pow, Signed}; fn check(x: i64, n: u32) { let big_x = BigInt::from(x); diff --git a/tests/torture.rs b/tests/torture.rs index 00f60b9..4f073d3 100644 --- a/tests/torture.rs +++ b/tests/torture.rs @@ -9,7 +9,6 @@ use num_traits::Zero; use rand::prelude::*; fn test_mul_divide_torture_count(count: usize) { - let bits_max = 1 << 12; let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; let mut rng = SmallRng::from_seed(seed); @@ -42,4 +41,3 @@ fn test_mul_divide_torture() { fn test_mul_divide_torture_long() { test_mul_divide_torture_count(1000000); } -