Skip to content

Commit

Permalink
Used copysign to avoid unnecessary branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phosphorus15 committed Aug 20, 2019
1 parent 64e3a10 commit 535efa4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
10 changes: 1 addition & 9 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 1 addition & 9 deletions src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 535efa4

Please sign in to comment.