GNU Info

Info Node: (libc.info)FP Comparison Functions

(libc.info)FP Comparison Functions


Next: Misc FP Arithmetic Prev: FP Bit Twiddling Up: Arithmetic Functions
Enter node , (file) or (file)node

Floating-Point Comparison Functions
-----------------------------------

   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.

 - Macro: int isgreater (_real-floating_ X, _real-floating_ Y)
     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.

 - Macro: int isgreaterequal (_real-floating_ X, _real-floating_ Y)
     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.

 - Macro: int isless (_real-floating_ X, _real-floating_ Y)
     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.

 - Macro: int islessequal (_real-floating_ X, _real-floating_ Y)
     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.

 - Macro: int islessgreater (_real-floating_ X, _real-floating_ Y)
     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.

 - Macro: int isunordered (_real-floating_ X, _real-floating_ Y)
     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.

   *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.


automatically generated by info2www version 1.2.2.9