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