]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/f32.rs
Auto merge of #103491 - cjgillot:self-rpit, r=oli-obk
[rust.git] / library / std / src / f32.rs
index 4127c4056f24ed8125bfe974439616a5394b1c53..4e30076246314edb50cdf017b1f1aa00878a3d12 100644 (file)
@@ -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.