From 918035e01eabc51554a97809f86175a6d7fdb773 Mon Sep 17 00:00:00 2001 From: nicoo Date: Sat, 30 May 2020 14:37:09 +0200 Subject: [PATCH] factor: Fix for old Rust --- src/uu/factor/build.rs | 2 +- src/uu/factor/src/numeric.rs | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/uu/factor/build.rs b/src/uu/factor/build.rs index 637c8981f..1677e44eb 100644 --- a/src/uu/factor/build.rs +++ b/src/uu/factor/build.rs @@ -58,7 +58,7 @@ fn main() { let mut x = primes.next().unwrap(); for next in primes { // format the table - let outstr = format!("({}, {}, {}),", x, inv_mod_u64(x), u64::MAX / x); + let outstr = format!("({}, {}, {}),", x, inv_mod_u64(x), std::u64::MAX / x); if cols + outstr.len() > MAX_WIDTH { write!(file, "\n {}", outstr).unwrap(); cols = 4 + outstr.len(); diff --git a/src/uu/factor/src/numeric.rs b/src/uu/factor/src/numeric.rs index ce25f81bf..38b98b620 100644 --- a/src/uu/factor/src/numeric.rs +++ b/src/uu/factor/src/numeric.rs @@ -40,12 +40,15 @@ pub(crate) trait Arithmetic: Copy + Sized { } // Check that r (reduced back to the usual representation) equals - // a^b % n, unless the latter computation overflows - debug_assert!(self - .to_u64(_a) - .checked_pow(_b as u32) - .map(|r| r % self.modulus() == self.to_u64(result)) - .unwrap_or(true)); + // a^b % n, unless the latter computation overflows + // Temporarily commented-out, as there u64::checked_pow is not available + // on the minimum supported Rust version, nor is an appropriate method + // for compiling the check conditionally. + //debug_assert!(self + // .to_u64(_a) + // .checked_pow(_b as u32) + // .map(|r| r % self.modulus() == self.to_u64(result)) + // .unwrap_or(true)); result } @@ -165,7 +168,7 @@ pub(crate) fn inv_mod_u64(a: u64) -> u64 { // special case when we're just starting out // This works because we know that // a does not divide 2^64, so floor(2^64 / a) == floor((2^64-1) / a); - u64::MAX + std::u64::MAX } else { r } / newr;