You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// assert_ne!(a, b); // a != b according to `PartialEq`.
1314
1293
/// ```
1315
1294
///
1316
-
/// # Examples
1295
+
/// ## Useful properties
1296
+
///
1297
+
/// The following corollaries follow from the above requirements for all values `a`, `b`, `c` of
1298
+
/// type `A`, `B`, `C`:
1299
+
///
1300
+
/// 1. `<` and `>` are [irreflexive](https://en.wikipedia.org/wiki/Irreflexive_relation). That is, if `A: PartialOrd<A>`, then:
1301
+
/// * `!(a < a)`.
1302
+
/// * `!(a > a)`.
1303
+
/// 2. `>`, `<=` and `>=` are also [transitive](https://en.wikipedia.org/wiki/Transitive_relation). That is, if `A: PartialOrd<B> + PartialOrd<C>` and `B:
1304
+
/// PartialOrd<C>`, then:
1305
+
/// * If `a > b` and `b > c`, then `a > c`.
1306
+
/// * If `a <= b` and `b <= c`, then `a <= c`.
1307
+
/// * If `a >= b` and `b >= c`, then `a >= c`.
1308
+
/// 3. `<` and `>` are [asymmetric](https://en.wikipedia.org/wiki/Asymmetric_relation). That is, if `A: PartialOrd<B>` and `B: PartialOrd<A>`, then:
1309
+
/// * If `a < b`, then `!(b < a)`;
1310
+
/// * If `a > b`, then `!(b > a)`.
1311
+
/// 4. `<=` and `>=` are [antisymmetric](https://en.wikipedia.org/wiki/Antisymmetric_relation) *modulo `==`*. That is, if `A: PartialOrd<B>` and `B: PartialOrd<A>`, then:
1312
+
/// * If `a <= b` and `b <= a`, then `a == b`.
1313
+
/// * If `a >= b` and `b >= a`, then `a == b`.
1314
+
/// * The converses of the above also hold: `a == b` implies `a <= b`, `b <= a`, `a >= b`, and `b >= a`.
1315
+
/// * Note that this is not antisymmetry in the usual sense, because `==` might not be the identity relation. (See below for further discussion.)
1316
+
/// 5. Duality of `partial_cmp`: if `A: PartialOrd<B>` and `B: PartialOrd<A>`, then
1317
+
/// `partial_cmp(a, b) == partial_cmp(b, a).map(Ordering::reverse)`
1318
+
///
1319
+
/// ## Strict and non-strict partial orders
1320
+
///
1321
+
/// For a type `T: PartialOrd`, the `<=` and `>=` relations are [partial orders](https://en.wikipedia.org/wiki/Partial_order)
1322
+
/// on the type's values *if and only if* `==` is the identity relation. (This can be shown from
1323
+
/// corollary 4.) However, this is not the case in general. For example, two distinct values can
1324
+
/// compare equal under `==`:
1317
1325
///
1318
1326
/// ```
1319
-
/// let x: u32 = 0;
1320
-
/// let y: u32 = 1;
1327
+
/// let a = -0.0;
1328
+
/// let b = +0.0;
1329
+
/// assert_ne!(a.to_bits(), b.to_bits()); // `a` and `b` are distinct because their sign bits differ.
1330
+
/// assert!(a == b); // Yet they are equal under `==`.
1331
+
/// assert!(a <= b && b <= a); // And so this is true (corollary 4).
1332
+
/// ```
1333
+
///
1334
+
/// And `==` may return `false`, even when comparing a value against itself:
1321
1335
///
1322
-
/// assert_eq!(x < y, true);
1323
-
/// assert_eq!(x.lt(&y), true);
1324
1336
/// ```
1337
+
/// let a = f64::sqrt(-1.0); // This produces a NaN.
1338
+
/// assert_eq!(a == a, false); // Which does not compare equal to any value.
1339
+
/// assert_eq!(a <= a, false); // Nor does it compare less than or equal to any value.
1340
+
/// ```
1341
+
///
1342
+
/// However, corollaries 1-3 imply that `<` and `>` satisfy the definition of a
0 commit comments