about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorEd Swartz <ed.swartz.258@gmail.com>2023-08-31 09:22:03 -0500
committerEd Swartz <ed.swartz.258@gmail.com>2023-10-07 11:19:27 -0500
commit8066079b5bc2f5d1ba09f389575957a9113e029a (patch)
tree1bffd024f1d38075953553f258d36bbc8dcc0206 /library/core/src
parent94bc9c737ea97d56f9b4076553ac37c05c1e3931 (diff)
downloadrust-8066079b5bc2f5d1ba09f389575957a9113e029a.tar.gz
rust-8066079b5bc2f5d1ba09f389575957a9113e029a.zip
Expose tests for {f32,f64}.total_cmp in docs, along with comment
Uncomment the assert! line and account and document that the sign
of NaN is not positive, necessarily.
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/num/f32.rs14
-rw-r--r--library/core/src/num/f64.rs14
2 files changed, 22 insertions, 6 deletions
diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs
index f60626b00dc..709eba2ffc9 100644
--- a/library/core/src/num/f32.rs
+++ b/library/core/src/num/f32.rs
@@ -1424,9 +1424,17 @@ impl f32 {
     /// ];
     ///
     /// bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
-    /// # assert!(bois.into_iter().map(|b| b.weight)
-    /// #     .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
-    /// #     .all(|(a, b)| a.to_bits() == b.to_bits()))
+    ///
+    /// // `f32::NAN` could be positive or negative, which will affect the sort order.
+    /// if f32::NAN.is_sign_negative() {
+    ///     assert!(bois.into_iter().map(|b| b.weight)
+    ///         .zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
+    ///         .all(|(a, b)| a.to_bits() == b.to_bits()))
+    /// } else {
+    ///     assert!(bois.into_iter().map(|b| b.weight)
+    ///         .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
+    ///         .all(|(a, b)| a.to_bits() == b.to_bits()))
+    /// }
     /// ```
     #[stable(feature = "total_cmp", since = "1.62.0")]
     #[must_use]
diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs
index 0a87021d8c1..73fa61574cc 100644
--- a/library/core/src/num/f64.rs
+++ b/library/core/src/num/f64.rs
@@ -1422,9 +1422,17 @@ impl f64 {
     /// ];
     ///
     /// bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
-    /// # assert!(bois.into_iter().map(|b| b.weight)
-    /// #     .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
-    /// #     .all(|(a, b)| a.to_bits() == b.to_bits()))
+    ///
+    /// // `f64::NAN` could be positive or negative, which will affect the sort order.
+    /// if f64::NAN.is_sign_negative() {
+    ///     assert!(bois.into_iter().map(|b| b.weight)
+    ///         .zip([f64::NAN, -5.0, 0.1, 10.0, 99.0, f64::INFINITY].iter())
+    ///         .all(|(a, b)| a.to_bits() == b.to_bits()))
+    /// } else {
+    ///     assert!(bois.into_iter().map(|b| b.weight)
+    ///         .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
+    ///         .all(|(a, b)| a.to_bits() == b.to_bits()))
+    /// }
     /// ```
     #[stable(feature = "total_cmp", since = "1.62.0")]
     #[must_use]