1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-05 07:27:46 +00:00

factor: Fix for old Rust

This commit is contained in:
nicoo 2020-05-30 14:37:09 +02:00
parent f84d0f9398
commit 918035e01e
2 changed files with 11 additions and 8 deletions

View file

@ -58,7 +58,7 @@ fn main() {
let mut x = primes.next().unwrap(); let mut x = primes.next().unwrap();
for next in primes { for next in primes {
// format the table // 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 { if cols + outstr.len() > MAX_WIDTH {
write!(file, "\n {}", outstr).unwrap(); write!(file, "\n {}", outstr).unwrap();
cols = 4 + outstr.len(); cols = 4 + outstr.len();

View file

@ -40,12 +40,15 @@ pub(crate) trait Arithmetic: Copy + Sized {
} }
// Check that r (reduced back to the usual representation) equals // Check that r (reduced back to the usual representation) equals
// a^b % n, unless the latter computation overflows // a^b % n, unless the latter computation overflows
debug_assert!(self // Temporarily commented-out, as there u64::checked_pow is not available
.to_u64(_a) // on the minimum supported Rust version, nor is an appropriate method
.checked_pow(_b as u32) // for compiling the check conditionally.
.map(|r| r % self.modulus() == self.to_u64(result)) //debug_assert!(self
.unwrap_or(true)); // .to_u64(_a)
// .checked_pow(_b as u32)
// .map(|r| r % self.modulus() == self.to_u64(result))
// .unwrap_or(true));
result result
} }
@ -165,7 +168,7 @@ pub(crate) fn inv_mod_u64(a: u64) -> u64 {
// special case when we're just starting out // special case when we're just starting out
// This works because we know that // This works because we know that
// a does not divide 2^64, so floor(2^64 / a) == floor((2^64-1) / a); // a does not divide 2^64, so floor(2^64 / a) == floor((2^64-1) / a);
u64::MAX std::u64::MAX
} else { } else {
r r
} / newr; } / newr;