]> git.proxmox.com Git - rustc.git/blobdiff - src/libstd/f64.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / libstd / f64.rs
index 6880294afcaafd4f41c40f6d0ef448f3b5bd14fd..ecaaf8323ab91a0b1105353a399af7182dca682a 100644 (file)
@@ -176,6 +176,35 @@ impl f64 {
         }
     }
 
+    /// Returns a number composed of the magnitude of `self` and the sign of
+    /// `y`.
+    ///
+    /// Equal to `self` if the sign of `self` and `y` are the same, otherwise
+    /// equal to `-self`. If `self` is a `NAN`, then a `NAN` with the sign of
+    /// `y` is returned.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(copysign)]
+    /// use std::f64;
+    ///
+    /// let f = 3.5_f64;
+    ///
+    /// assert_eq!(f.copysign(0.42), 3.5_f64);
+    /// assert_eq!(f.copysign(-0.42), -3.5_f64);
+    /// assert_eq!((-f).copysign(0.42), 3.5_f64);
+    /// assert_eq!((-f).copysign(-0.42), -3.5_f64);
+    ///
+    /// assert!(f64::NAN.copysign(1.0).is_nan());
+    /// ```
+    #[inline]
+    #[must_use]
+    #[unstable(feature="copysign", issue="55169")]
+    pub fn copysign(self, y: f64) -> f64 {
+        unsafe { intrinsics::copysignf64(self, y) }
+    }
+
     /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
     /// error, yielding a more accurate result than an unfused multiply-add.
     ///