uint
uint copied to clipboard
`pow`: A dedicated function avoiding full-sized shift.
On 2022-05-31 @recmo wrote in c1a0c34
“Merge pull request #97 from recmo/isqrt”:
A dedicated function avoiding full-sized shift.
#[allow(clippy::cast_sign_loss)] // fract >= 0.
let bits = (fract.exp2() * EXP2_63) as u64;
// Note: If `fract` is zero this will result in `u64::MAX`.
if shift >= 63 {
// OPT: A dedicated function avoiding full-sized shift.
Some(Self::try_from(bits).ok()?.checked_shl(shift - 63)?)
} else {
let shift = 63 - shift;
// Divide `bits` by `2^shift`, rounding to nearest.
let bits = (bits >> shift) + ((bits >> (shift - 1)) & 1);
From src/pow.rs:129