]> git.lizzy.rs Git - rust.git/commitdiff
Used `copysign` to avoid unnecessary branches.
authorPhosphorus15 <steepout@qq.com>
Tue, 20 Aug 2019 04:39:12 +0000 (12:39 +0800)
committerPhosphorus15 <steepout@qq.com>
Tue, 20 Aug 2019 04:39:12 +0000 (12:39 +0800)
src/libstd/f32.rs
src/libstd/f64.rs

index ba75650fc4cb092e521ae79c89af0bb46b839060..dcb035993ae39532401c49c5f54584b47670eed5 100644 (file)
@@ -910,15 +910,7 @@ pub fn tanh(self) -> f32 {
     pub fn asinh(self) -> f32 {
         match self {
             x if x == NEG_INFINITY => NEG_INFINITY,
-            x if x.is_sign_negative() => {
-                let v = (x + ((x * x) + 1.0).sqrt()).ln();
-                if v.is_sign_negative() {
-                    v
-                } else {
-                    -v
-                }
-            }
-            x => (x + ((x * x) + 1.0).sqrt()).ln()
+            x => (x + ((x * x) + 1.0).sqrt()).ln().copysign(self)
         }
     }
 
index 62c659739de79a9cb514a7ea0fc00df1e31f44c4..076b6340d89bc22422692099957be2ba560290e4 100644 (file)
@@ -833,15 +833,7 @@ pub fn tanh(self) -> f64 {
     pub fn asinh(self) -> f64 {
         match self {
             x if x == NEG_INFINITY => NEG_INFINITY,
-            x if x.is_sign_negative() => {
-                let v = (x + ((x * x) + 1.0).sqrt()).ln();
-                if v.is_sign_negative() {
-                    v
-                } else {
-                    -v
-                }
-            }
-            x => (x + ((x * x) + 1.0).sqrt()).ln()
+            x => (x + ((x * x) + 1.0).sqrt()).ln().copysign(self)
         }
     }