Next: , Previous: infinity, Up: Math


1.31 isgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered—comparison macros

Synopsis

     #include <math.h>
     int isgreater(real-floating x, real-floating y);
     int isgreaterequal(real-floating x, real-floating y);
     int isless(real-floating x, real-floating y);
     int islessequal(real-floating x, real-floating y);
     int islessgreater(real-floating x, real-floating y);
     int isunordered(real-floating x, real-floating y);
     

Description
isgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered are macros defined for use in comparing floating-point numbers without raising any floating-point exceptions.

The relational operators (i.e. <, >, <=, and >=) support the usual mathematical relationships between numeric values. For any ordered pair of numeric values exactly one of the relationships–less, greater, and equal–is true. Relational operators may raise the "invalid" floating-point exception when argument values are NaNs. For a NaN and a numeric value, or for two NaNs, just the unordered relationship is true (i.e., if one or both of the arguments a NaN, the relationship is called unordered). The specified macros are quiet (non floating-point exception raising) versions of the relational operators, and other comparison macros that facilitate writing efficient code that accounts for NaNs without suffering the "invalid" floating-point exception. In the synopses shown, "real-floating" indicates that the argument is an expression of real floating type.

Please note that saying that the macros do not raise floating-point exceptions, it is referring to the function that they are performing. It is certainly possible to give them an expression which causes an exception. For example:

NaN < 1.0
causes an "invalid" exception,
isless(NaN, 1.0)
does not, and
isless(NaN*0., 1.0)
causes an exception due to the "NaN*0.", but not from the resultant reduced comparison of isless(NaN, 1.0).

Returns
No floating-point exceptions are raised for any of the macros.
The isgreater macro returns the value of (x) > (y).
The isgreaterequal macro returns the value of (x) >= (y).
The isless macro returns the value of (x) < (y).
The islessequal macro returns the value of (x) <= (y).
The islessgreater macro returns the value of (x) < (y) || (x) > (y).
The isunordered macro returns 1 if either of its arguments is NaN and 0 otherwise.

Portability
C99, POSIX.