Used copysign to avoid unnecessary branches.

This commit is contained in:
Phosphorus15 2019-08-20 12:39:12 +08:00
parent 64e3a10a82
commit 535efa4afd
2 changed files with 2 additions and 18 deletions

View file

@ -910,15 +910,7 @@ impl f32 {
pub fn asinh(self) -> f32 {
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()
x => (x + ((x * x) + 1.0).sqrt()).ln().copysign(self)
}
}

View file

@ -833,15 +833,7 @@ impl f64 {
pub fn asinh(self) -> f64 {
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()
x => (x + ((x * x) + 1.0).sqrt()).ln().copysign(self)
}
}