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()
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.