X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Fstd%2Fsrc%2Ff32.rs;h=4e30076246314edb50cdf017b1f1aa00878a3d12;hb=7fe6f36224e92db6fbde952e0b7e50863161f6ee;hp=4127c4056f24ed8125bfe974439616a5394b1c53;hpb=bfd637a3cf85b80453db4a6e39802163b07319f7;p=rust.git diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index 4127c4056f2..4e300762463 100644 --- a/library/std/src/f32.rs +++ b/library/std/src/f32.rs @@ -880,7 +880,9 @@ pub fn tanh(self) -> f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asinh(self) -> f32 { - (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. @@ -900,7 +902,11 @@ pub fn asinh(self) -> f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn acosh(self) -> f32 { - 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.