Name
isless, islessequal, islessgreater
Synopsis
Compares two floating-point values without risking an exception
#include <math.h> intisless(x,y); intislessequal(x,y); intislessgreater(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.
Example
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()
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access