]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/f64.rs
Rollup merge of #107391 - notriddle:notriddle/copy-path-button, r=GuillaumeGomez
[rust.git] / library / std / src / f64.rs
index cc64258da60d1a63fdc44ef0f72f41d07e2ab976..ec67fdad4f726f50ac11d503701fef61ab8664b5 100644 (file)
@@ -882,7 +882,9 @@ pub fn tanh(self) -> 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 @@ pub fn asinh(self) -> 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.