Skip to content

Commit fb7948e

Browse files
authored
Rollup merge of #78627 - est31:total_cmp_no_superset, r=m-ou-se
Point out that total_cmp is no strict superset of partial comparison Partial comparison and total_cmp are not equal. This helps preventing the mistake of creating float wrappers that base their Ord impl on total_cmp and their PartialOrd impl on the PartialOrd impl of the float type. PartialOrd and Ord [are required to agree with each other](https://doc.rust-lang.org/std/cmp/trait.Ord.html#how-can-i-implement-ord).
2 parents 7baf48f + a79059d commit fb7948e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: library/core/src/num/f32.rs

+4
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ impl f32 {
876876
/// - Positive signaling NaN
877877
/// - Positive quiet NaN
878878
///
879+
/// Note that this function does not always agree with the [`PartialOrd`]
880+
/// and [`PartialEq`] implementations of `f32`. In particular, they regard
881+
/// negative and positive zero as equal, while `total_cmp` doesn't.
882+
///
879883
/// # Example
880884
/// ```
881885
/// #![feature(total_cmp)]

Diff for: library/core/src/num/f64.rs

+4
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,10 @@ impl f64 {
890890
/// - Positive signaling NaN
891891
/// - Positive quiet NaN
892892
///
893+
/// Note that this function does not always agree with the [`PartialOrd`]
894+
/// and [`PartialEq`] implementations of `f64`. In particular, they regard
895+
/// negative and positive zero as equal, while `total_cmp` doesn't.
896+
///
893897
/// # Example
894898
/// ```
895899
/// #![feature(total_cmp)]

0 commit comments

Comments
 (0)