diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-11-02 14:14:38 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-02 14:14:38 +0900 |
| commit | fb7948e7c1aa0ff6ce4cbde45cde2384d1d1ba10 (patch) | |
| tree | 92d3e9f2f78de13e4967a7300fd1cfbbe1527c4a | |
| parent | 7baf48ffc0eb94f15165191d5b2808822995ac82 (diff) | |
| parent | a79059d42d8f6b1e2c2f109aa55a8ff98f4eb453 (diff) | |
| download | rust-fb7948e7c1aa0ff6ce4cbde45cde2384d1d1ba10.tar.gz rust-fb7948e7c1aa0ff6ce4cbde45cde2384d1d1ba10.zip | |
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).
| -rw-r--r-- | library/core/src/num/f32.rs | 4 | ||||
| -rw-r--r-- | library/core/src/num/f64.rs | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index bf7c87f685d..86e6352d132 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -876,6 +876,10 @@ impl f32 { /// - Positive signaling NaN /// - Positive quiet NaN /// + /// Note that this function does not always agree with the [`PartialOrd`] + /// and [`PartialEq`] implementations of `f32`. In particular, they regard + /// negative and positive zero as equal, while `total_cmp` doesn't. + /// /// # Example /// ``` /// #![feature(total_cmp)] diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index e31e176ba1b..9b1405b479f 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -890,6 +890,10 @@ impl f64 { /// - Positive signaling NaN /// - Positive quiet NaN /// + /// Note that this function does not always agree with the [`PartialOrd`] + /// and [`PartialEq`] implementations of `f64`. In particular, they regard + /// negative and positive zero as equal, while `total_cmp` doesn't. + /// /// # Example /// ``` /// #![feature(total_cmp)] |
