Added negative cases for asinh according to IEEE-754.

This commit is contained in:
Phosphorus15 2019-08-19 17:22:08 +08:00
parent 92f08b78a1
commit c4569347b2
2 changed files with 22 additions and 8 deletions

View File

@ -908,10 +908,17 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn asinh(self) -> f32 {
if self == NEG_INFINITY {
NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln()
match self {
x if x == NEG_INFINITY => NEG_INFINITY,
x if x.is_sign_negative() => {
let v = (x + ((x * x) + 1.0).sqrt()).ln();
if v.is_sign_negative() {
v
} else {
-v
}
}
x => (x + ((x * x) + 1.0).sqrt()).ln()
}
}

View File

@ -831,10 +831,17 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn asinh(self) -> f64 {
if self == NEG_INFINITY {
NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln()
match self {
x if x == NEG_INFINITY => NEG_INFINITY,
x if x.is_sign_negative() => {
let v = (x + ((x * x) + 1.0).sqrt()).ln();
if v.is_sign_negative() {
v
} else {
-v
}
}
x => (x + ((x * x) + 1.0).sqrt()).ln()
}
}