Improve accuracy of asinh and acosh
This commit is contained in:
parent
b6097f2e1b
commit
26b23f4a37
4 changed files with 32 additions and 4 deletions
|
@ -882,7 +882,9 @@ impl f64 {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn asinh(self) -> f64 {
|
||||
(self.abs() + ((self * self) + 1.0).sqrt()).ln().copysign(self)
|
||||
let ax = self.abs();
|
||||
let ix = 1.0 / ax;
|
||||
(ax + (ax / (Self::hypot(1.0, ix) + ix))).ln_1p().copysign(self)
|
||||
}
|
||||
|
||||
/// Inverse hyperbolic cosine function.
|
||||
|
@ -902,7 +904,11 @@ impl f64 {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn acosh(self) -> f64 {
|
||||
if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
|
||||
if self < 1.0 {
|
||||
Self::NAN
|
||||
} else {
|
||||
(self + ((self - 1.0).sqrt() * (self + 1.0).sqrt())).ln()
|
||||
}
|
||||
}
|
||||
|
||||
/// Inverse hyperbolic tangent function.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue