Skip to content

Commit

Permalink
Expose tests for {f32,f64}.total_cmp in docs, along with comment
Browse files Browse the repository at this point in the history
Uncomment the assert! line and account for the sign of NaN not
being positive, necessarily.
  • Loading branch information
eswartz committed Oct 6, 2023
1 parent 94bc9c7 commit cfc285d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 10 additions & 3 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,9 +1424,16 @@ 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()))
///
/// 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]
Expand Down
16 changes: 13 additions & 3 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,19 @@ 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()))
/// ```
/// Since the NaN constant does not have a well-defined sign,
/// this test may result in either:
/// ```
/// assert!(bois.into_iter().map(|b| b.weight)

Check failure on line 1429 in library/core/src/num/f64.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check

cannot find value `bois` in this scope
/// .zip([-5.0, 0.1, 10.0, 99.0, f64::INFINITY, f64::NAN].iter())
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
/// ```
/// or:
/// ```
/// assert!(bois.into_iter().map(|b| b.weight)

Check failure on line 1435 in library/core/src/num/f64.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check

cannot find value `bois` in this scope
/// .zip([f64::NAN, -5.0, 0.1, 10.0, 99.0, f64::INFINITY].iter())
/// .all(|(a, b)| a.to_bits() == b.to_bits()))
/// ```
#[stable(feature = "total_cmp", since = "1.62.0")]
#[must_use]
Expand Down

0 comments on commit cfc285d

Please sign in to comment.