Floating point comparison operations

Factor handbook » The language » Numbers » Floats

Factor handbook » The language » Numbers » Floats

Prev: | Bitwise operations on floats |

In mathematics, real numbers are linearly ordered; for any two numbers a and b, exactly one of the following is true:

With floating point values, there is a fourth possibility; a and b 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).

The ordered comparison operators set floating point exception flags if the result of the comparison is unordered. The standard comparison operators ( <, <=, >, >= ) perform ordered comparisons.

The number= operation performs an unordered comparison. The following set of operators also perform unordered comparisons:

A word to check if two values are unordered with respect to each other:

To test for floating point exceptions, use the math.floats.env vocabulary.

If neither input to a comparison operator is a floating point value, then u<, u<=, u> and u>= are equivalent to the ordered operators.

a < b
a = b
a > b

With floating point values, there is a fourth possibility; a and b 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).

The ordered comparison operators set floating point exception flags if the result of the comparison is unordered. The standard comparison operators ( <, <=, >, >= ) perform ordered comparisons.

The number= 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 vocabulary.

If neither input to a comparison operator is a floating point value, then u<, u<=, u> and u>= are equivalent to the ordered operators.

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.99 x86.64 (2203, heads/master-424edf64aa, Mar 8 2023 13:48:50)