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

Fix asinh of negative values #72486

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ impl f32 {
if self == Self::NEG_INFINITY {
Self::NEG_INFINITY
} else {
Ralith marked this conversation as resolved.
Show resolved Hide resolved
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
(self.abs() + ((self * self) + 1.0).sqrt()).ln().copysign(self)
}
}

Expand Down Expand Up @@ -1414,6 +1414,8 @@ mod tests {
assert!((-0.0f32).asinh().is_sign_negative()); // issue 63271
assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
// regression test for the catastrophic cancellation fixed in 72486
assert_approx_eq!((-3000.0f32).asinh(), -8.699514775987968673236893537700647f32);
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ impl f64 {
if self == Self::NEG_INFINITY {
Self::NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
(self.abs() + ((self * self) + 1.0).sqrt()).ln().copysign(self)
}
}

Expand Down Expand Up @@ -1443,6 +1443,8 @@ mod tests {
// issue 63271
assert_approx_eq!(2.0f64.asinh(), 1.443635475178810342493276740273105f64);
assert_approx_eq!((-2.0f64).asinh(), -1.443635475178810342493276740273105f64);
// regression test for the catastrophic cancellation fixed in 72486
assert_approx_eq!((-67452098.07139316f64).asinh(), -18.72007542627454439398548429400083);
}

#[test]
Expand Down