Skip to content

Commit 6416e2e

Browse files
committed
Auto merge of #115412 - eswartz:docs/total_cmp-test-result-in-docs, r=scottmcm
Expose tests for {f32,f64}.total_cmp in docs Expose tests for {f32,f64}.total_cmp in docs Uncomment the helpful `assert_eq!` line, which is stripped out completely in docs, and leaves the reader to mentally play through the algorithm, or go to the playground and add a println!, to see what the result will be. (If these tests are known to fail on some platforms, is there some mechanism to conditionalize this or escape the test so the `assert_eq!` source will be visible on the web? I am a newbie, which is why I was reading docs ;)
2 parents 61d3b26 + 8066079 commit 6416e2e

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

library/core/src/num/f32.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,17 @@ 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+
/// // `f32::NAN` could be positive or negative, which will affect the sort order.
1429+
/// if f32::NAN.is_sign_negative() {
1430+
/// assert!(bois.into_iter().map(|b| b.weight)
1431+
/// .zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
1432+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1433+
/// } else {
1434+
/// assert!(bois.into_iter().map(|b| b.weight)
1435+
/// .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
1436+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1437+
/// }
14301438
/// ```
14311439
#[stable(feature = "total_cmp", since = "1.62.0")]
14321440
#[must_use]

library/core/src/num/f64.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,17 @@ 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+
/// // `f64::NAN` could be positive or negative, which will affect the sort order.
1427+
/// if f64::NAN.is_sign_negative() {
1428+
/// assert!(bois.into_iter().map(|b| b.weight)
1429+
/// .zip([f64::NAN, -5.0, 0.1, 10.0, 99.0, f64::INFINITY].iter())
1430+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1431+
/// } else {
1432+
/// assert!(bois.into_iter().map(|b| b.weight)
1433+
/// .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
1434+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1435+
/// }
14281436
/// ```
14291437
#[stable(feature = "total_cmp", since = "1.62.0")]
14301438
#[must_use]

0 commit comments

Comments
 (0)