Skip to content

Commit f5df406

Browse files
committed
Fix for 32-bit architectures
1 parent 294ce40 commit f5df406

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/hazmat/primecount.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ fn ln<const LIMBS: usize>(x: &Uint<LIMBS>) -> u64 {
2323
let log2_x = U256::from(x.bits_vartime().saturating_sub(1));
2424
// The error in this approximation is "lower 128 bits of the product"/2^128, which is on the order of 10^-40.
2525
let ln_x: U256 = (log2_x * SCALED_LN2) >> 128;
26+
#[cfg(target_pointer_width = "32")]
27+
let ln_x = (ln_x.as_limbs()[1].0 as u64) << 32 | ln_x.as_limbs()[0].0 as u64;
28+
#[cfg(target_pointer_width = "64")]
2629
let ln_x = ln_x.as_limbs()[0].0;
2730
ln_x & !((ln_x == 0) as u64) // Ensure we return 0 for ln(1)
2831
}

0 commit comments

Comments
 (0)