Skip to content

Commit bbd448a

Browse files
committed
auto merge of #14733 : sfackler/rust/partial-eq-nan-docs, r=alexcrichton
It is in fact the case that `NaN != NaN`. The true relations for compareQuietNotEqual are LT, GT *and* UN. I also rephrased the docs for PartialOrd since floats are not the only types which are not totally ordered.
2 parents fa18328 + 6b3d380 commit bbd448a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/libcore/cmp.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
4040
/// Trait for values that can be compared for equality and inequality.
4141
///
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`.
4645
///
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`.
4950
///
5051
/// Eventually, this will be implemented by default for types that implement
5152
/// `Eq`.
@@ -147,9 +148,10 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
147148
/// PartialOrd only requires implementation of the `lt` method,
148149
/// with the others generated from default implementations.
149150
///
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).
153155
#[lang="ord"]
154156
pub trait PartialOrd: PartialEq {
155157
/// This method tests less than (for `self` and `other`) and is used by the `<` operator.

0 commit comments

Comments
 (0)