Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pow: Round negative to zero. #100

Open
github-actions bot opened this issue May 31, 2022 · 0 comments
Open

pow: Round negative to zero. #100

github-actions bot opened this issue May 31, 2022 · 0 comments
Assignees
Labels
feature tracker Issue tracked by bot

Comments

@github-actions
Copy link

On 2022-05-31 @recmo wrote in c1a0c34 “Merge pull request #97 from recmo/isqrt”:

Round negative to zero.
Self::BITS ~< 2^52 and so fits f64.

    #[must_use]
    pub fn approx_pow2(exp: f64) -> Option<Self> {
        const LN2_1P5: f64 = 0.584_962_500_721_156_2_f64;
        const EXP2_63: f64 = 9_223_372_036_854_775_808_f64;

        // FEATURE: Round negative to zero.
        #[allow(clippy::cast_precision_loss)] // Self::BITS ~< 2^52 and so fits f64.
        if exp < LN2_1P5 {
            if exp < -1.0 {
                return Some(Self::ZERO);
            }
            return Self::try_from(1).ok();

From src/pow.rs:101

@github-actions github-actions bot added feature tracker Issue tracked by bot labels May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature tracker Issue tracked by bot
Projects
None yet
Development

No branches or pull requests

1 participant