diff --git a/basm-std/src/math.rs b/basm-std/src/math.rs index 2e6b99b0..3468c4cd 100644 --- a/basm-std/src/math.rs +++ b/basm-std/src/math.rs @@ -500,7 +500,9 @@ mod test { assert_eq!(Some(4i64), modinv(3i64, 11i64)); assert_eq!(Some(4u64), modinv(3u64, 11u64)); let p = 0u64.wrapping_sub((1u64 << 32) - 1); - assert_eq!(Some((p + 1) / 2), modinv(2u64, p)); + #[allow(clippy::manual_div_ceil)] + let p_half = (p + 1) / 2; + assert_eq!(Some(p_half), modinv(2u64, p)); assert_eq!(Some(9999999966u64), modinv(9999999966u64, 9999999967u64)); assert_eq!(Some(12297829382473034411u64), modinv(3, 0u64)); assert_eq!( diff --git a/basm-std/src/math/ntt.rs b/basm-std/src/math/ntt.rs index 2e4ebbf7..b6ccdb88 100644 --- a/basm-std/src/math/ntt.rs +++ b/basm-std/src/math/ntt.rs @@ -25,10 +25,10 @@ mod test { 1614279433659886989, 2232618956921417485 ], - multiply_u64(&[2745895686766400144, 7520886206723962441], &[ - 9006621652498007052, - 5476023620144815056 - ]) + multiply_u64( + &[2745895686766400144, 7520886206723962441], + &[9006621652498007052, 5476023620144815056] + ) ); } #[test] diff --git a/basm-std/src/math/ntt/nttcore.rs b/basm-std/src/math/ntt/nttcore.rs index dfeb9ec1..4ec77cb5 100644 --- a/basm-std/src/math/ntt/nttcore.rs +++ b/basm-std/src/math/ntt/nttcore.rs @@ -849,9 +849,9 @@ pub fn pack_into(src: &[u64], dst1: &mut [u64], dst2: &mut [u64], bits: u64) { pub const fn compute_bits(l: u64) -> u64 { let total_bits = l * 64; - let (mut lo, mut hi) = (42, 62); + let (mut lo, mut hi) = (42u64, 62u64); while lo < hi { - let mid = (lo + hi + 1) / 2; + let mid = (lo + hi).div_ceil(2); let single_digit_max_val = (1u64 << mid) - 1; let l_corrected = total_bits.div_ceil(mid); let (lhs, overflow) = (single_digit_max_val as u128) diff --git a/basm-std/src/math/ntt/polyops.rs b/basm-std/src/math/ntt/polyops.rs index 3bec6147..e8d95f1b 100644 --- a/basm-std/src/math/ntt/polyops.rs +++ b/basm-std/src/math/ntt/polyops.rs @@ -28,11 +28,11 @@ pub fn polyneginv_u64(h: &[u64], n: usize, modulo: u64) -> Option> { a[0] = modulo - h0_inv; let mut d = vec![n]; while *d.last().unwrap() > 1 { - d.push((d.last().unwrap() + 1) / 2); + d.push(d.last().unwrap().div_ceil(2)); } d.pop(); let mut l = 1; - let mut h1a_c = vec![0; (n + 1) / 2]; + let mut h1a_c = vec![0; n.div_ceil(2)]; for &target_len in d.iter().rev() { let e = min(h.len(), target_len); let t = min(l + e - 1, target_len); diff --git a/basm-std/src/math/reeds_sloane.rs b/basm-std/src/math/reeds_sloane.rs index 0eda926f..93532a93 100644 --- a/basm-std/src/math/reeds_sloane.rs +++ b/basm-std/src/math/reeds_sloane.rs @@ -24,7 +24,7 @@ fn reeds_sloane_prime_power(first_terms: &[u64], p: u64, e: usize) -> Vec { // Returns (theta, u) let (mut lo, mut hi) = (0, e); while lo < hi { - let mid = (lo + hi + 1) / 2; + let mid = (lo + hi).div_ceil(2); #[allow(clippy::collapsible_else_if)] if ppow[mid] == 0 { if x == 0 {