Previous Page
Next Page

isless, islessequal, islessgreater

Compares two floating-point values without risking an exception

#include <math.h>
int isless ( x , y  );
int islessequal ( x , y  );
int islessgreater ( x , y  );

The macro isless( ) tests whether the argument x is less than the argument y, but without risking an exception. Both operands must have real floating-point types. The result of isless( ) is the same as the result of the operation (x) < ( y), but that operation could raise an "invalid operand" exception if either operand is NaN ("not a number"), in which case neither is greater than, equal to, or less than the other.

The macro isless( ) returns a nonzero value (that is, true) if the first argument is less than the second; otherwise, it returns 0. The macro islessequal( ) functions similarly, but corresponds to the relation (x) <= ( y), returning true if the first argument is less than or equal to the second; otherwise 0. The macro islessgreater( ) is also similar, but corresponds to the expression (x) < ( y) || (x) > ( y), returning TRue if the first argument is less than or greater than the second; otherwise 0.


double minimum( double a, double b )
  if ( islessgreater( a, b ) )
    return ( isless( a, b ) ? a : b );
  if ( a == b )
    return a;
  feraiseexcept( FE_INVALID );
  return NAN;

See Also

isgreater( ), isgreaterequal( ), isunordered( )

Previous Page
Next Page