1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-03 06:27:45 +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();
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();

View file

@ -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;