Overview of Comparison Operators¶
Equality operators return BOOL; the three-way operator <=> returns
ORDER::LESS, ORDER::EQUAL, or ORDER::GREATER.
VAR low I32 := 2;
VAR high I32 := 5;
ASSERT(low != high);
ASSERT(low < high);
ASSERT(low <= high);
ASSERT((low <=> high) == ORDER::LESS);
Three-way comparison¶
<=> is useful when code needs the relationship itself:
VAR relationship ORDER := left <=> right;
IF (relationship == ORDER::GREATER)
{
use_right_first();
}
User-defined types can provide .OPERATOR<=>; Quxlang derives <, >, <=,
and >= from its ORDER result.
::coordinate STRUCT
{
.value VAR I32;
.OPERATOR<=> FUNCTION(@OTHER CONST& coordinate): ORDER
{
RETURN .value <=> OTHER.value;
}
}
A user-defined .OPERATOR== expresses an equality contract directly. Quxlang
derives != by negating equality.
Comparable categories¶
Primitive numbers, BOOL, enums, flagsets, type indexes, addresses, compatible
pointers, arrays, and eligible structural values provide built-in or generated
comparison. Floating-point operators use Quxlang's strong total ordering.
Polymorphic structs do not receive generated comparison; see
Inheritance.
Reference¶
See the Comparison Operators Reference for supported categories, overload dispatch order, generated lexicographic comparison, pointer constraints, and floating-point ordering boundaries.