Next: Misc FP Arithmetic, Previous: FP Bit Twiddling, Up: Arithmetic Functions [Contents][Index]
The standard C comparison operators provoke exceptions when one or other of the operands is NaN. For example,
int v = a < 1.0;
will raise an exception if a is NaN. (This does not
happen with ==
and !=
; those merely return false and true,
respectively, when NaN is examined.) Frequently this exception is
undesirable. ISO C99 therefore defines comparison functions that
do not raise exceptions when NaN is examined. All of the functions are
implemented as macros which allow their arguments to be of any
floating-point type. The macros are guaranteed to evaluate their
arguments only once.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This macro determines whether the argument x is greater than
y. It is equivalent to (x) > (y)
, but no
exception is raised if x or y are NaN.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This macro determines whether the argument x is greater than or
equal to y. It is equivalent to (x) >= (y)
, but no
exception is raised if x or y are NaN.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This macro determines whether the argument x is less than y.
It is equivalent to (x) < (y)
, but no exception is
raised if x or y are NaN.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This macro determines whether the argument x is less than or equal
to y. It is equivalent to (x) <= (y)
, but no
exception is raised if x or y are NaN.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This macro determines whether the argument x is less or greater
than y. It is equivalent to (x) < (y) ||
(x) > (y)
(although it only evaluates x and y
once), but no exception is raised if x or y are NaN.
This macro is not equivalent to x != y
, because that
expression is true if x or y are NaN.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This macro determines whether its arguments are unordered. In other words, it is true if x or y are NaN, and false otherwise.
Not all machines provide hardware support for these operations. On machines that don’t, the macros can be very slow. Therefore, you should not use these functions when NaN is not a concern.
NB: There are no macros isequal
or isunequal
.
They are unnecessary, because the ==
and !=
operators do
not throw an exception if one or both of the operands are NaN.
Next: Misc FP Arithmetic, Previous: FP Bit Twiddling, Up: Arithmetic Functions [Contents][Index]