uint icon indicating copy to clipboard operation
uint copied to clipboard

`pow`: A dedicated function avoiding full-sized shift.

Open github-actions[bot] opened this issue 2 years ago • 0 comments

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

github-actions[bot] avatar May 31 '22 20:05 github-actions[bot]