mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
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.
This commit is contained in:
parent
94bc9c737e
commit
8066079b5b
@ -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]
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user