diff --git a/ci/big_quickcheck/src/lib.rs b/ci/big_quickcheck/src/lib.rs index 57dd8b73..41018a69 100644 --- a/ci/big_quickcheck/src/lib.rs +++ b/ci/big_quickcheck/src/lib.rs @@ -42,7 +42,7 @@ fn quickcheck_signed_eq_symmetric(a: BigInt, b: BigInt) -> bool { #[test] fn quickcheck_arith_primitive() { - let gen = Gen::new(usize::max_value()); + let gen = Gen::new(usize::MAX); let mut qc = QuickCheck::new().gen(gen); fn test_unsigned_add_primitive(a: usize, b: usize) -> TestResult { @@ -280,7 +280,7 @@ fn quickcheck_signed_conversion(a: BigInt, radix: u8) -> TestResult { #[test] fn quicktest_shift() { - let gen = Gen::new(usize::max_value()); + let gen = Gen::new(usize::MAX); let mut qc = QuickCheck::new().gen(gen); fn test_shr_unsigned(a: u64, shift: u8) -> TestResult { @@ -317,7 +317,7 @@ fn quicktest_shift() { #[test] fn quickcheck_modpow() { - let gen = Gen::new(usize::max_value()); + let gen = Gen::new(usize::MAX); let mut qc = QuickCheck::new().gen(gen); fn simple_modpow(base: &BigInt, exponent: &BigInt, modulus: &BigInt) -> BigInt { @@ -360,7 +360,7 @@ fn quickcheck_modpow() { #[test] fn quickcheck_modinv() { - let gen = Gen::new(usize::max_value()); + let gen = Gen::new(usize::MAX); let mut qc = QuickCheck::new().gen(gen); fn test_modinv(value: i128, modulus: i128) -> TestResult { @@ -417,7 +417,7 @@ fn quickcheck_modinv() { #[test] fn quickcheck_to_float_equals_i128_cast() { - let gen = Gen::new(usize::max_value()); + let gen = Gen::new(usize::MAX); let mut qc = QuickCheck::new().gen(gen).tests(1_000_000); fn to_f32_equals_i128_cast(value: i128) -> bool { diff --git a/ci/big_serde/src/lib.rs b/ci/big_serde/src/lib.rs index 68c2551b..4ee7b632 100644 --- a/ci/big_serde/src/lib.rs +++ b/ci/big_serde/src/lib.rs @@ -155,7 +155,7 @@ fn bad_size_hint( assert_tokens(&T::one(), &tokens); tokens[prefix.len()] = Token::Seq { - len: Some(usize::max_value()), + len: Some(usize::MAX), }; catch_unwind(|| assert_ser_tokens(&T::one(), &tokens)).unwrap_err(); diff --git a/src/bigint.rs b/src/bigint.rs index 704bb95b..ffd457da 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -8,8 +8,6 @@ use core::fmt; use core::hash; use core::ops::{Neg, Not}; use core::str; -use core::{i128, u128}; -use core::{i64, u64}; use num_integer::{Integer, Roots}; use num_traits::{ConstZero, Num, One, Pow, Signed, Zero}; diff --git a/src/bigint/bits.rs b/src/bigint/bits.rs index dfb86645..93cd24c4 100644 --- a/src/bigint/bits.rs +++ b/src/bigint/bits.rs @@ -36,7 +36,7 @@ fn negate_carry(a: BigDigit, acc: &mut DoubleBigDigit) -> BigDigit { // + 1 & -ff = ...0 01 & ...f 01 = ...0 01 = + 1 // +ff & - 1 = ...0 ff & ...f ff = ...0 ff = +ff // answer is pos, has length of a -fn bitand_pos_neg(a: &mut Vec, b: &[BigDigit]) { +fn bitand_pos_neg(a: &mut [BigDigit], b: &[BigDigit]) { let mut carry_b = 1; for (ai, &bi) in a.iter_mut().zip(b.iter()) { let twos_b = negate_carry(bi, &mut carry_b); @@ -202,7 +202,7 @@ fn bitor_pos_neg(a: &mut Vec, b: &[BigDigit]) { // - 1 | +ff = ...f ff | ...0 ff = ...f ff = - 1 // -ff | + 1 = ...f 01 | ...0 01 = ...f 01 = -ff // answer is neg, has length of a -fn bitor_neg_pos(a: &mut Vec, b: &[BigDigit]) { +fn bitor_neg_pos(a: &mut [BigDigit], b: &[BigDigit]) { let mut carry_a = 1; let mut carry_or = 1; for (ai, &bi) in a.iter_mut().zip(b.iter()) { diff --git a/src/bigint/convert.rs b/src/bigint/convert.rs index f1cc2ff9..f0c29c49 100644 --- a/src/bigint/convert.rs +++ b/src/bigint/convert.rs @@ -50,7 +50,7 @@ impl ToPrimitive for BigInt { let m: u64 = 1 << 63; match n.cmp(&m) { Less => Some(-(n as i64)), - Equal => Some(core::i64::MIN), + Equal => Some(i64::MIN), Greater => None, } } @@ -67,7 +67,7 @@ impl ToPrimitive for BigInt { let m: u128 = 1 << 127; match n.cmp(&m) { Less => Some(-(n as i128)), - Equal => Some(core::i128::MIN), + Equal => Some(i128::MIN), Greater => None, } } @@ -179,7 +179,7 @@ impl From for BigInt { if n >= 0 { BigInt::from(n as u64) } else { - let u = core::u64::MAX - (n as u64) + 1; + let u = u64::MAX - (n as u64) + 1; BigInt { sign: Minus, data: BigUint::from(u), @@ -194,7 +194,7 @@ impl From for BigInt { if n >= 0 { BigInt::from(n as u128) } else { - let u = core::u128::MAX - (n as u128) + 1; + let u = u128::MAX - (n as u128) + 1; BigInt { sign: Minus, data: BigUint::from(u), diff --git a/src/biguint.rs b/src/biguint.rs index 9bcd8966..41506055 100644 --- a/src/biguint.rs +++ b/src/biguint.rs @@ -8,7 +8,6 @@ use core::fmt; use core::hash; use core::mem; use core::str; -use core::{u32, u64, u8}; use num_integer::{Integer, Roots}; use num_traits::{ConstZero, Num, One, Pow, ToPrimitive, Unsigned, Zero}; @@ -410,7 +409,7 @@ impl Roots for BigUint { _ => { // Try to guess by scaling down such that it does fit in `f64`. // With some (x * 2ⁿᵏ), its nth root ≈ (ⁿ√x * 2ᵏ) - let extra_bits = bits - (core::f64::MAX_EXP as u64 - 1); + let extra_bits = bits - (f64::MAX_EXP as u64 - 1); let root_scale = Integer::div_ceil(&extra_bits, &n64); let scale = root_scale * n64; if scale < bits && bits - scale > n64 { @@ -458,7 +457,7 @@ impl Roots for BigUint { _ => { // Try to guess by scaling down such that it does fit in `f64`. // With some (x * 2²ᵏ), its sqrt ≈ (√x * 2ᵏ) - let extra_bits = bits - (core::f64::MAX_EXP as u64 - 1); + let extra_bits = bits - (f64::MAX_EXP as u64 - 1); let root_scale = (extra_bits + 1) / 2; let scale = root_scale * 2; (self >> scale).sqrt() << root_scale @@ -499,7 +498,7 @@ impl Roots for BigUint { _ => { // Try to guess by scaling down such that it does fit in `f64`. // With some (x * 2³ᵏ), its cbrt ≈ (∛x * 2ᵏ) - let extra_bits = bits - (core::f64::MAX_EXP as u64 - 1); + let extra_bits = bits - (f64::MAX_EXP as u64 - 1); let root_scale = (extra_bits + 2) / 3; let scale = root_scale * 3; (self >> scale).cbrt() << root_scale @@ -1032,9 +1031,7 @@ impl BigUint { // Note: we're saturating `digit_index` and `new_len` -- any such case is guaranteed to // fail allocation, and that's more consistent than adding our own overflow panics. let bits_per_digit = u64::from(big_digit::BITS); - let digit_index = (bit / bits_per_digit) - .to_usize() - .unwrap_or(core::usize::MAX); + let digit_index = (bit / bits_per_digit).to_usize().unwrap_or(usize::MAX); let bit_mask = (1 as BigDigit) << (bit % bits_per_digit); if value { if digit_index >= self.data.len() { @@ -1176,28 +1173,17 @@ cfg_digit!( fn test_u32_u128() { assert_eq!(u32_from_u128(0u128), (0, 0, 0, 0)); assert_eq!( - u32_from_u128(u128::max_value()), - ( - u32::max_value(), - u32::max_value(), - u32::max_value(), - u32::max_value() - ) + u32_from_u128(u128::MAX), + (u32::MAX, u32::MAX, u32::MAX, u32::MAX) ); - assert_eq!( - u32_from_u128(u32::max_value() as u128), - (0, 0, 0, u32::max_value()) - ); + assert_eq!(u32_from_u128(u32::MAX as u128), (0, 0, 0, u32::MAX)); - assert_eq!( - u32_from_u128(u64::max_value() as u128), - (0, 0, u32::max_value(), u32::max_value()) - ); + assert_eq!(u32_from_u128(u64::MAX as u128), (0, 0, u32::MAX, u32::MAX)); assert_eq!( - u32_from_u128((u64::max_value() as u128) + u32::max_value() as u128), - (0, 1, 0, u32::max_value() - 1) + u32_from_u128((u64::MAX as u128) + u32::MAX as u128), + (0, 1, 0, u32::MAX - 1) ); assert_eq!(u32_from_u128(36_893_488_151_714_070_528), (0, 2, 1, 0)); @@ -1209,11 +1195,11 @@ fn test_u128_u32_roundtrip() { let values = vec![ 0u128, 1u128, - u64::max_value() as u128 * 3, - u32::max_value() as u128, - u64::max_value() as u128, - (u64::max_value() as u128) + u32::max_value() as u128, - u128::max_value(), + u64::MAX as u128 * 3, + u32::MAX as u128, + u64::MAX as u128, + (u64::MAX as u128) + u32::MAX as u128, + u128::MAX, ]; for val in &values { diff --git a/src/biguint/addition.rs b/src/biguint/addition.rs index 4ad00a8c..a054e66d 100644 --- a/src/biguint/addition.rs +++ b/src/biguint/addition.rs @@ -194,7 +194,7 @@ impl AddAssign for BigUint { cfg_digit!( #[inline] fn add_assign(&mut self, other: u128) { - if other <= u128::from(u64::max_value()) { + if other <= u128::from(u64::MAX) { *self += other as u64 } else { let (a, b, c, d) = super::u32_from_u128(other); diff --git a/src/biguint/convert.rs b/src/biguint/convert.rs index 384b5f44..18c74bb3 100644 --- a/src/biguint/convert.rs +++ b/src/biguint/convert.rs @@ -69,7 +69,7 @@ fn from_inexact_bitwise_digits_le(v: &[u8], bits: u8) -> BigUint { let total_bits = (v.len() as u64).saturating_mul(bits.into()); let big_digits = Integer::div_ceil(&total_bits, &big_digit::BITS.into()) .to_usize() - .unwrap_or(core::usize::MAX); + .unwrap_or(usize::MAX); let mut data = Vec::with_capacity(big_digits); let mut d = 0; @@ -245,7 +245,7 @@ impl Num for BigUint { b'a'..=b'z' => b - b'a' + 10, b'A'..=b'Z' => b - b'A' + 10, b'_' => continue, - _ => core::u8::MAX, + _ => u8::MAX, }; if d < radix as u8 { v.push(d); @@ -372,8 +372,8 @@ impl ToPrimitive for BigUint { let mantissa = high_bits_to_u64(self); let exponent = self.bits() - u64::from(fls(mantissa)); - if exponent > core::f32::MAX_EXP as u64 { - Some(core::f32::INFINITY) + if exponent > f32::MAX_EXP as u64 { + Some(f32::INFINITY) } else { Some((mantissa as f32) * 2.0f32.powi(exponent as i32)) } @@ -384,8 +384,8 @@ impl ToPrimitive for BigUint { let mantissa = high_bits_to_u64(self); let exponent = self.bits() - u64::from(fls(mantissa)); - if exponent > core::f64::MAX_EXP as u64 { - Some(core::f64::INFINITY) + if exponent > f64::MAX_EXP as u64 { + Some(f64::INFINITY) } else { Some((mantissa as f64) * 2.0f64.powi(exponent as i32)) } @@ -607,7 +607,7 @@ pub(super) fn to_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec { let digits_per_big_digit = big_digit::BITS / bits; let digits = Integer::div_ceil(&u.bits(), &u64::from(bits)) .to_usize() - .unwrap_or(core::usize::MAX); + .unwrap_or(usize::MAX); let mut res = Vec::with_capacity(digits); for mut r in u.data[..last_i].iter().cloned() { @@ -633,7 +633,7 @@ fn to_inexact_bitwise_digits_le(u: &BigUint, bits: u8) -> Vec { let mask: BigDigit = (1 << bits) - 1; let digits = Integer::div_ceil(&u.bits(), &u64::from(bits)) .to_usize() - .unwrap_or(core::usize::MAX); + .unwrap_or(usize::MAX); let mut res = Vec::with_capacity(digits); let mut r = 0; @@ -845,7 +845,7 @@ fn test_radix_bases() { for radix in 3u32..256 { if !radix.is_power_of_two() { let (base, power) = get_radix_base(radix); - let radix = BigDigit::try_from(radix).unwrap(); + let radix = BigDigit::from(radix); let power = u32::try_from(power).unwrap(); assert_eq!(base, radix.pow(power)); assert!(radix.checked_pow(power + 1).is_none()); @@ -858,7 +858,7 @@ fn test_half_radix_bases() { for radix in 3u32..256 { if !radix.is_power_of_two() { let (base, power) = get_half_radix_base(radix); - let radix = BigDigit::try_from(radix).unwrap(); + let radix = BigDigit::from(radix); let power = u32::try_from(power).unwrap(); assert_eq!(base, radix.pow(power)); assert!(radix.pow(power + 1) > big_digit::HALF); diff --git a/src/biguint/shift.rs b/src/biguint/shift.rs index f603537a..edcbc158 100644 --- a/src/biguint/shift.rs +++ b/src/biguint/shift.rs @@ -58,7 +58,7 @@ fn biguint_shr(n: Cow<'_, BigUint>, shift: T) -> BigUint { return n.into_owned(); } let bits = T::from(big_digit::BITS).unwrap(); - let digits = (shift / bits).to_usize().unwrap_or(core::usize::MAX); + let digits = (shift / bits).to_usize().unwrap_or(usize::MAX); let shift = (shift % bits).to_u8().unwrap(); biguint_shr2(n, digits, shift) } diff --git a/src/macros.rs b/src/macros.rs index ab821907..f2e21e3b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -2,19 +2,19 @@ macro_rules! cfg_32 { ($($any:tt)+) => { - #[cfg(not(any(target_pointer_width = "64", target_pointer_width = "128")))] $($any)+ + #[cfg(not(target_pointer_width = "64"))] $($any)+ } } macro_rules! cfg_32_or_test { ($($any:tt)+) => { - #[cfg(any(not(any(target_pointer_width = "64", target_pointer_width = "128")), test))] $($any)+ + #[cfg(any(not(target_pointer_width = "64"), test))] $($any)+ } } macro_rules! cfg_64 { ($($any:tt)+) => { - #[cfg(any(target_pointer_width = "64", target_pointer_width = "128"))] $($any)+ + #[cfg(target_pointer_width = "64")] $($any)+ } } diff --git a/tests/bigint.rs b/tests/bigint.rs index 75cf81ec..fea5232e 100644 --- a/tests/bigint.rs +++ b/tests/bigint.rs @@ -8,9 +8,6 @@ use std::hash::{BuildHasher, Hash, Hasher}; use std::iter::repeat; use std::ops::Neg; use std::{f32, f64}; -use std::{i128, u128}; -use std::{i16, i32, i64, i8, isize}; -use std::{u16, u32, u64, u8, usize}; use num_integer::Integer; use num_traits::{ diff --git a/tests/bigint_bitwise.rs b/tests/bigint_bitwise.rs index 6c1e82fe..94d92e1d 100644 --- a/tests/bigint_bitwise.rs +++ b/tests/bigint_bitwise.rs @@ -1,6 +1,5 @@ use num_bigint::{BigInt, Sign, ToBigInt}; use num_traits::ToPrimitive; -use std::{i32, i64, u32}; enum ValueVec { N, diff --git a/tests/biguint.rs b/tests/biguint.rs index c027771b..4e2c6259 100644 --- a/tests/biguint.rs +++ b/tests/biguint.rs @@ -6,12 +6,9 @@ use num_integer::Integer; 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::{f32, f64}; -use std::{i128, u128}; -use std::{u16, u32, u64, u8, usize}; use num_traits::{ pow, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Euclid, FromBytes, FromPrimitive, Num, diff --git a/tests/consts/mod.rs b/tests/consts/mod.rs index 5d0555d0..457fbd36 100644 --- a/tests/consts/mod.rs +++ b/tests/consts/mod.rs @@ -16,7 +16,7 @@ pub const SUM_TRIPLES: &[(&[u32], &[u32], &[u32])] = &[ (&[1, 2, 2, 1], &[N1, N2], &[0, 1, 3, 1]), ]; -pub const M: u32 = ::std::u32::MAX; +pub const M: u32 = u32::MAX; pub const MUL_TRIPLES: &[(&[u32], &[u32], &[u32])] = &[ (&[], &[], &[]), (&[], &[1], &[]), diff --git a/tests/roots.rs b/tests/roots.rs index cfef80c4..7110adf9 100644 --- a/tests/roots.rs +++ b/tests/roots.rs @@ -1,7 +1,6 @@ mod biguint { use num_bigint::BigUint; use num_traits::{One, Zero}; - use std::{i32, u32}; fn check>(x: T, n: u32) { let x: BigUint = x.into();