Previous Page
Next Page

isgreater, isgreaterequal

Compares two floating-point values without risking an exception

#include <math.h>
int isgreater ( x , y  );
int isgreaterequal ( x , y  );

The macro isgreater( ) tests whether the argument x is greater than the argument y, but without risking an exception. Both operands must have real floating-point types. The result of isgreater( ) 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 isgreater( ) returns a nonzero value (that is, true) if the first argument is greater than the second; otherwise, it returns 0. The macro isgreaterequal( ) functions similarly, but corresponds to the relation (x) >= ( y), returning true if the first argument is greater than or equal to the second; otherwise 0.

Example

/* Can a, b, and c be three sides of a triangle? */
double a, b, c, temp;
/* First get the longest "side" in a. */
if ( isgreater( a, b ) )
   temp = a; a = b; b = temp;
if ( isgreater( a, c ) )
   temp = a; a = c; c = temp;
/* Then see if a is longer than the sum of the other two sides: */
if ( isgreaterequal( a, b + c ) )
  printf( "The three numbers %.2lf, %.2lf, and %.2lf "
          "are not sides of a triangle.\n", a, b, c );

See Also

isless( ), islessequal( ), islessgreater( ), isunordered( )


Previous Page
Next Page