Skip to content

Commit 2a62677

Browse files
committed
Expose tests for {f32,f64}.total_cmp in docs, along with comment
Uncomment the assert! line and account for the sign of NaN not being positive, necessarily.
1 parent 94bc9c7 commit 2a62677

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

library/core/src/num/f32.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,16 @@ 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+
/// if f32::NAN.is_sign_negative() {
1429+
/// assert!(bois.into_iter().map(|b| b.weight)
1430+
/// .zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
1431+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1432+
/// } else {
1433+
/// assert!(bois.into_iter().map(|b| b.weight)
1434+
/// .zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
1435+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1436+
/// }
14301437
/// ```
14311438
#[stable(feature = "total_cmp", since = "1.62.0")]
14321439
#[must_use]

library/core/src/num/f64.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,16 @@ 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+
/// if f64::NAN.is_sign_negative() {
1427+
/// assert!(bois.into_iter().map(|b| b.weight)
1428+
/// .zip([f64::NAN, -5.0, 0.1, 10.0, 99.0, f64::INFINITY].iter())
1429+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1430+
/// } else {
1431+
/// assert!(bois.into_iter().map(|b| b.weight)
1432+
/// .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
1433+
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
1434+
/// }
14281435
/// ```
14291436
#[stable(feature = "total_cmp", since = "1.62.0")]
14301437
#[must_use]

0 commit comments

Comments
 (0)