In mathematics, real numbers are linearly ordered; for any two numbers a
, exactly one of the following is true:
a < b
a = b
a > b
With floating point values, there is a fourth possibility; a
may be unordered
. This happens if one or both values are Not-a-Number values.
All comparison operators, including number=
, return f
in the unordered case (and in particular, this means that a NaN is not equal to itself).
comparison operators set floating point exception flags if the result of the comparison is unordered. The standard comparison operators ( <
) perform ordered comparisons.
operation performs an unordered comparison. The following set of operators also perform unordered comparisons:
u< ( x y -- ? )
u<= ( x y -- ? )
u> ( x y -- ? )
u>= ( x y -- ? )
A word to check if two values are unordered with respect to each other:
unordered? ( x y -- ? )
To test for floating point exceptions, use the math.floats.env
If neither input to a comparison operator is a floating point value, then u<
are equivalent to the ordered operators.