diff options
Diffstat (limited to 'src/udiv128.rs')
-rw-r--r-- | src/udiv128.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/udiv128.rs b/src/udiv128.rs index 617c1c1..0587047 100644 --- a/src/udiv128.rs +++ b/src/udiv128.rs @@ -1,5 +1,9 @@ +#[cfg(feature = "no-panic")] +use no_panic::no_panic; + /// Multiply unsigned 128 bit integers, return upper 128 bits of the result #[inline] +#[cfg_attr(feature = "no-panic", no_panic)] fn u128_mulhi(x: u128, y: u128) -> u128 { let x_lo = x as u64; let x_hi = (x >> 64) as u64; @@ -12,7 +16,7 @@ fn u128_mulhi(x: u128, y: u128) -> u128 { let high1 = m >> 64; let m_lo = m as u64; - let high2 = x_hi as u128 * y_lo as u128 + m_lo as u128 >> 64; + let high2 = (x_hi as u128 * y_lo as u128 + m_lo as u128) >> 64; x_hi as u128 * y_hi as u128 + high1 + high2 } @@ -26,15 +30,14 @@ fn u128_mulhi(x: u128, y: u128) -> u128 { /// Implementation, 1994, pp. 61–72 /// #[inline] +#[cfg_attr(feature = "no-panic", no_panic)] pub fn udivmod_1e19(n: u128) -> (u128, u64) { let d = 10_000_000_000_000_000_000_u64; // 10^19 let quot = if n < 1 << 83 { ((n >> 19) as u64 / (d >> 19)) as u128 } else { - let factor = - (8507059173023461586_u64 as u128) << 64 | 10779635027931437427 as u128; - u128_mulhi(n, factor) >> 62 + u128_mulhi(n, 156927543384667019095894735580191660403) >> 62 }; let rem = (n - quot * d as u128) as u64; |