Name
isunordered
Synopsis
Tests whether two floating-point values can be numerically ordered
#include <math.h> int isunordered(x,y)
The macro isunordered()
tests whether any ordered relation exists between two floating-point
values, without risking an “invalid operand” exception in case
either of them is NaN (“not a number”). Both operands must have real
floating-point types. Two floating-point values are be said to be
ordered if one is either less than, equal to, or greater than the
other. If either or both of them are NaN, then they are unordered.
isunordered() returns a nonzero
value (that is, true) if no
ordered relation obtains between the two arguments.
Example
double maximum( double a, double b )
{
if ( isinf( a ) ) // +Inf > anything; -Inf < anything
return ( signbit( a ) ? b : a );
if ( isinf( b ) )
return ( signbit( b ) ? a : b );
if (isunordered( a, b ) )
{
feraiseexcept( FE_INVALID );
return NAN;
}
return ( a > b ? a : b );
}See Also
isgreater(), isgreaterequal(), isless(), islessequal(), islessgreater()
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