Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 08f10c2

Browse files
committedOct 6, 2023
Expose tests for {f32,f64}.total_cmp in docs, along with comment
Reformat so the helpful assert_eq! line, which is stripped out completely in docs due to being commented out. Apparently, according to discussion, the result may differ on other architectures or LLVM versions, so show the two potential results.
1 parent 94bc9c7 commit 08f10c2

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed
 

‎library/core/src/num/f32.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,19 @@ impl f32 {
14241424
/// ];
14251425
///
14261426
/// bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
1427-
/// # assert!(bois.into_iter().map(|b| b.weight)
1428-
/// # .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
1429-
/// # .all(|(a, b)| a.to_bits() == b.to_bits()))
1427+
/// ```
1428+
/// Since the NaN constant does not have a well-defined sign,
1429+
/// this test may result in either:
1430+
/// ```
1431+
/// assert!(bois.into_iter().map(|b| b.weight)
1432+
/// .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
1433+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1434+
/// ```
1435+
/// or:
1436+
/// ```
1437+
/// assert!(bois.into_iter().map(|b| b.weight)
1438+
/// .zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
1439+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
14301440
/// ```
14311441
#[stable(feature = "total_cmp", since = "1.62.0")]
14321442
#[must_use]

‎library/core/src/num/f64.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,19 @@ impl f64 {
14221422
/// ];
14231423
///
14241424
/// bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
1425-
/// # assert!(bois.into_iter().map(|b| b.weight)
1426-
/// # .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
1427-
/// # .all(|(a, b)| a.to_bits() == b.to_bits()))
1425+
/// ```
1426+
/// Since the NaN constant does not have a well-defined sign,
1427+
/// this test may result in either:
1428+
/// ```
1429+
/// assert!(bois.into_iter().map(|b| b.weight)
1430+
/// .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
1431+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1432+
/// ```
1433+
/// or:
1434+
/// ```
1435+
/// assert!(bois.into_iter().map(|b| b.weight)
1436+
/// .zip([f64::NAN, -5.0, 0.1, 10.0, 99.0, f64::INFINITY].iter())
1437+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
14281438
/// ```
14291439
#[stable(feature = "total_cmp", since = "1.62.0")]
14301440
#[must_use]

0 commit comments

Comments
 (0)
Please sign in to comment.