Home / Docs / Specification / 29. Numerics

29.5 Equality and order

Release v0.4.0
  1. == is identity. x == y exactly when x.to_bits() == y.to_bits(). So nan() == nan() is true, and -0.0 == 0.0 is false. != is its negation.
  2. < is IEEE totalOrder: -infinity() < negative finite values < -0.0 < 0.0 < positive finite values < infinity() < nan(). x <= y is x < y or x == y.
  3. IEEE comparison is the methods of §3 rule 3, x.ieee_lt(other: y) and the others.
  4. Consequences. == is reflexive, symmetric and transitive, on F64 and on every value that holds one; < is a strict total order, so sort is deterministic, -0.0 sorts before 0.0 and NaN last; Map[F64, V] holds -0.0 and 0.0 as two keys and NaN as one key.
  5. Comparing with a literal zero is an error. Every comparison of an F64 with an operand that is a float literal of value zero, with or without unary - (0.0, -0.0, 0.000), on either side, is U2033: ==, !=, <, <=, > and >=, is, and a when arm. The repairs: x.is_zero(), x.is_positive_zero() or x.is_negative_zero() for an equality; x.ieee_lt(other: 0.0) and the other IEEE methods, then x.is_sign_negative(), for an ordering. No other comparison changes.
  6. Other literal patterns. A when arm whose pattern is any other float literal or a range, and is with such a literal, are U2032, with a repair to an if that compares by == or by an IEEE method. for does not iterate over F64.