|
39 | 39 |
|
40 | 40 | /// Trait for values that can be compared for equality and inequality.
|
41 | 41 | ///
|
42 |
| -/// This trait allows partial equality, where types can be unordered instead of |
43 |
| -/// strictly equal or unequal. For example, with the built-in floating-point |
44 |
| -/// types `a == b` and `a != b` will both evaluate to false if either `a` or |
45 |
| -/// `b` is NaN (cf. IEEE 754-2008 section 5.11). |
| 42 | +/// This trait allows for partial equality, for types that do not have an |
| 43 | +/// equivalence relation. For example, in floating point numbers `NaN != NaN`, |
| 44 | +/// so floating point types implement `PartialEq` but not `Eq`. |
46 | 45 | ///
|
47 |
| -/// PartialEq only requires the `eq` method to be implemented; `ne` is its negation by |
48 |
| -/// default. |
| 46 | +/// PartialEq only requires the `eq` method to be implemented; `ne` is defined |
| 47 | +/// in terms of it by default. Any manual implementation of `ne` *must* respect |
| 48 | +/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and |
| 49 | +/// only if `a != b`. |
49 | 50 | ///
|
50 | 51 | /// Eventually, this will be implemented by default for types that implement
|
51 | 52 | /// `Eq`.
|
@@ -147,9 +148,10 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
|
147 | 148 | /// PartialOrd only requires implementation of the `lt` method,
|
148 | 149 | /// with the others generated from default implementations.
|
149 | 150 | ///
|
150 |
| -/// However it remains possible to implement the others separately, |
151 |
| -/// for compatibility with floating-point NaN semantics |
152 |
| -/// (cf. IEEE 754-2008 section 5.11). |
| 151 | +/// However it remains possible to implement the others separately for types |
| 152 | +/// which do not have a total order. For example, for floating point numbers, |
| 153 | +/// `NaN < 0 == false` and `NaN >= 0 == false` (cf. IEEE 754-2008 section |
| 154 | +/// 5.11). |
153 | 155 | #[lang="ord"]
|
154 | 156 | pub trait PartialOrd: PartialEq {
|
155 | 157 | /// This method tests less than (for `self` and `other`) and is used by the `<` operator.
|
|
0 commit comments