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.
(x) > (y)
, but no
exception is raised if x or y are NaN.
(x) >= (y)
, but no
exception is raised if x or y are NaN.
(x) < (y)
, but no exception is
raised if x or y are NaN.
(x) <= (y)
, but no
exception is raised if x or y are NaN.
(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.
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.
Note: 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.
Go to the first, previous, next, last section, table of contents.