about summary refs log tree commit diff
diff options
context:
space:
mode:
authorcyberia <cyberia@donk.systems>2021-07-07 18:22:17 +0100
committercyberia <cyberia@donk.systems>2021-07-07 18:22:17 +0100
commita853a49425c042ffd2d0d46883537a6fc85dddba (patch)
treee8d615ac1af60433fe0119a0cb9fd668fae7bf2f
parentc5e344f7747dbd7e7d4b209e3c480deb5979a56f (diff)
downloadrust-a853a49425c042ffd2d0d46883537a6fc85dddba.tar.gz
rust-a853a49425c042ffd2d0d46883537a6fc85dddba.zip
Clarify behaviour of f64 and f32::sqrt when argument is negative zero
-rw-r--r--library/std/src/f32.rs4
-rw-r--r--library/std/src/f64.rs4
2 files changed, 6 insertions, 2 deletions
diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs
index 21bd79611a5..e0cc6ad1d42 100644
--- a/library/std/src/f32.rs
+++ b/library/std/src/f32.rs
@@ -324,18 +324,20 @@ impl f32 {
 
     /// Returns the square root of a number.
     ///
-    /// Returns NaN if `self` is a negative number.
+    /// Returns NaN if `self` is a negative number other than `-0.0`.
     ///
     /// # Examples
     ///
     /// ```
     /// let positive = 4.0_f32;
     /// let negative = -4.0_f32;
+    /// let negative_zero = -0.0_f32;
     ///
     /// let abs_difference = (positive.sqrt() - 2.0).abs();
     ///
     /// assert!(abs_difference <= f32::EPSILON);
     /// assert!(negative.sqrt().is_nan());
+    /// assert!(negative_zero.sqrt() == negative_zero);
     /// ```
     #[must_use = "method returns a new number and does not mutate the original value"]
     #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs
index 8c8cf73741b..7ed65b7dafe 100644
--- a/library/std/src/f64.rs
+++ b/library/std/src/f64.rs
@@ -324,18 +324,20 @@ impl f64 {
 
     /// Returns the square root of a number.
     ///
-    /// Returns NaN if `self` is a negative number.
+    /// Returns NaN if `self` is a negative number other than `-0.0`.
     ///
     /// # Examples
     ///
     /// ```
     /// let positive = 4.0_f64;
     /// let negative = -4.0_f64;
+    /// let negative_zero = -0.0_f64;
     ///
     /// let abs_difference = (positive.sqrt() - 2.0).abs();
     ///
     /// assert!(abs_difference < 1e-10);
     /// assert!(negative.sqrt().is_nan());
+    /// assert!(negative_zero.sqrt() == negative_zero);
     /// ```
     #[must_use = "method returns a new number and does not mutate the original value"]
     #[stable(feature = "rust1", since = "1.0.0")]