Ordering
enum · Source line 53
pub enum Ordering { Less, Equal, Greater, }No item documentation at this pin.
wolf-std d58f9e1
· toolchain pin verified against wolf 0.2.41 (0261597).
Source signatures and documentation; execution support is stated in each module.
All modules · Plain text · Stability tier: core
std.cmp — comparison and ordering: the Ordering enum, the Eq and Ord protocols, and the min/max/clamp family. Stability tier: core.
Decided here and recorded (sc01): f64 ordering. Its Ord is total_cmp (IEEE totalOrder), so sorting floats is legal and NaN has one home (above +inf). See total_cmp for the two documented approximations at the current pins.
**f64 HAS AN Eq NOW, AND sc44 REVERSED sc01 TO GIVE IT ONE.** This header said for forty-three sprints that f64 has no Eq because "IEEE partial comparison stays on the builtin operators". [type.trait.op] (s155, wolf-lang#5) is what retires that sentence: since the operator bridge landed, == on a type parameter IS Eq.eq, so "stays on the builtin operator" and "goes through Eq" stopped being two different places. Withholding the impl would not have kept a partial order out of a total protocol; it would only have made f64 the one primitive whose == does not work under a bound, while < under the same bound did. The impl's body is self == other — the clause's rule that a primitive impl IS the builtin operation — and the law caveat is stated on the impl itself: reflexivity fails at NaN, which is exactly what the builtin does and is why Ord for f64 is total_cmp and not this.
INTERIM SPELLINGS (each filed, flipped on the pin bump that fixes it): - The absence-spelling interim is RETIRED (F-0003, dead at the sc05 pins, renamed tree-wide at sc06): a lowercase bare tag resolves in every implementation. Until sc12 this line still described the interim, in a half-renamed sentence that said the source said the opposite of what it says. - Ord requires Eq by doctrine, and the requirement is still DOCUMENTARY, but for a smaller reason than it was. s155 gave the grammar a trait_item with an = form (the alias bound, [type.trait.op.alias]) and no supertrait clause, so composition this edition is an alias listing both and not trait Ord: Eq. F-0004's operator half is RULED — ==, != and the relationals dispatch through Eq/Ord by name on a type parameter or a user type, which is what std.ops is written against — and its supertrait half is what remains open. - **F-0006 IS RETIRED AND impl Ord for str SHIPS.** The finding said "wolfc rejects < on str (E0409) and one rejected body poisons every test that imports this module". Re-measured at the sc44 pins on all three lanes: cmp.Ord.cmp("a", "b").is_lt() is true on the checked tier, the body passes the static ladder on every lane, and nothing is poisoned. The impl is written here in the same shape as Ord for int — two relational tests and a fallthrough — and the order it reports is the language's byte-lexicographic one ([mem.str.order]), which std.sort's sort_strs already documents is not alphabetical in any human language (F-0019 owns collation).
enum · Source line 53
pub enum Ordering { Less, Equal, Greater, }No item documentation at this pin.
trait · Source line 141
pub trait Eq { fn eq(self, other: Self) -> bool }Equivalence. Law: eq is reflexive, symmetric, transitive; Ord implementors agree with it (cmp(a, b).is_eq() == Eq.eq(a, b)).
trait · Source line 148
pub trait Ord { fn cmp(self, other: Self) -> Ordering }Total order. Law: trichotomy (exactly one of Less/Equal/Greater), antisymmetry, transitivity. Requires Eq by doctrine (see the module header for why the requirement is documentary today).
fn · Source line 65
pub fn reverse(self) -> OrderingThe opposite verdict: Less <-> Greater; Equal is its own reverse. Total: no error row, no traps.
Example (prose until enum methods execute at the pins, F-0002): total_cmp(1.0, 2.0).reverse() is Greater.
fn · Source line 76
pub fn then(self, other: Ordering) -> OrderingLexicographic composition: keep self unless it is Equal, in which case defer to other. Chains multi-key comparisons: by_name.then(by_id). Total: no error row, no traps.
fn · Source line 85
pub fn is_lt(self) -> boolTrue exactly for Less. Total: no error row, no traps.
fn · Source line 94
pub fn is_le(self) -> boolTrue for Less or Equal. Total: no error row, no traps.
fn · Source line 103
pub fn is_eq(self) -> boolTrue exactly for Equal. Total: no error row, no traps.
fn · Source line 112
pub fn is_ne(self) -> boolTrue for anything but Equal. Total: no error row, no traps.
fn · Source line 121
pub fn is_ge(self) -> boolTrue for Greater or Equal. Total: no error row, no traps.
fn · Source line 130
pub fn is_gt(self) -> boolTrue exactly for Greater. Total: no error row, no traps.
fn · Source line 327
pub fn min[T: Ord](a: T, b: T) -> TLeast of a and b under Ord; returns a on a tie (the stable choice). Total: no error row, no traps.
fn · Source line 337
pub fn max[T: Ord](a: T, b: T) -> TGreatest of a and b under Ord; returns a on a tie (the stable choice). Total: no error row, no traps.
fn · Source line 348
pub fn clamp[T: Ord](v: T, lo: T, hi: T) -> Tv limited to [lo, hi]: lo when v < lo, hi when v > hi, else v. Traps assert when lo > hi — a contract violation the callee cannot repair ([conf.trap.map]: user assertions).
fn · Source line 410
pub fn total_cmp(a: f64, b: f64) -> OrderingIEEE totalOrder over floats, monomorphic: -inf < negative reals < -0.0 < +0.0 < positive reals < +inf < NaN. Total: no error row, no traps (f64 division by zero is IEEE, not a trap — X3 governs integers).
Two documented approximations at the current pins (no f64 bit intrinsics exist to do better): NaN is one value — the sign and payload of a NaN are not observed, so every NaN sorts above +inf and all NaNs compare Equal; totalOrder's -NaN-below--inf home is not represented.
Back in the fence at sc47, verbatim, as sc44 promised. These four lines were a wolf-doc-example from sc01 to sc43, went to prose at sc44 when == between two Orderings became fail(E0301) on both compiler rungs (the operator trait resolved by BARE name, and an importer of this module has only cmp.Eq), and wolf-lang#336 closed that in v0.2.12. Measured here at 0.2.12/0.1.34: all four lines, all three lanes, exit(0).
Each line is true: total_cmp(1.0, 2.0) agrees with total_cmp(-1.0e9, 3.5) (both Less), total_cmp(2.0, 1.0) with total_cmp(0.0 / 0.0, 1.0) (both Greater — NaN above every real), total_cmp(4.5, 4.5) with total_cmp(0.0 / 0.0, 0.0 / 0.0) (both Equal — all NaNs are one value here), and total_cmp(-0.0, 0.0) with total_cmp(1.0, 2.0) (both Less — the sign of zero is observed).
cmp.total_cmp(1.0, 2.0) == cmp.total_cmp(-1.0e9, 3.5)
cmp.total_cmp(2.0, 1.0) == cmp.total_cmp(0.0 / 0.0, 1.0)
cmp.total_cmp(4.5, 4.5) == cmp.total_cmp(0.0 / 0.0, 0.0 / 0.0)
cmp.total_cmp(-0.0, 0.0) == cmp.total_cmp(1.0, 2.0)No public declarations in this section.
No public declarations in this section.