Skip to content

f32/64::asinh() should return -0.0 for -0.0 #63271

Description

@TimothyGu

Currently, both of the following return false:

(-0.0 as f64).asinh().is_sign_negative()
(-0.0 as f32).asinh().is_sign_negative()

However, in other languages like C, asinh(-0.0) would always return -0.0. We might need another fast case for 0.0 and -0.0 here:

rust/src/libstd/f64.rs

Lines 833 to 839 in f01b9f8

pub fn asinh(self) -> f64 {
if self == NEG_INFINITY {
NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln()
}
}

Activity

  1. nagisa commented on Aug 4, 2019

    @nagisa
    Member

    IEEE-754 (2008), section 9.2.1:

    For the functions expm1, exp2m1, exp10m1, logp1, log2p1, log10p1, sin, tan, sinPi, atanPi, asin, atan, sinh, tanh, asinh, and atanh, f(+0) is +0 and f(−0) is −0 with no exception.

    and

    sinh(±∞) and asinh(±∞) are ±∞ with no exception.

  2. Phosphorus15 commented on Aug 19, 2019

    @Phosphorus15
    Contributor

    I don't think adding a fast case for -0.0 is enough, codes like

    println!("{}", (-1e-20f64).asinh().is_sign_negative());

    also reports to be false, considering that asinh is a monotone function.
    (-0.0 as f64).asinh().is_sign_negative() and (-1e-20f64).asinh().is_sign_negative() should have the same result considering that -0.0 is strictly larger than -1e-20f.
    Maybe it is more sound to add a case for any given floating number that is negative, and negate the result if it turns out not to be negative.

  3. added 2 commits that reference this issue on Aug 27, 2019
    c8a352e
    68597c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions