December 2005
Beginner to intermediate
618 pages
20h 19m
English
isnan
Tests whether a given floating-point value is “not a number”
#include <math.h> intisnan( floatx); intisnan( doublex); intisnan( long doublex);
The macro isnan() yields a
nonzero value (that is, true) if
its argument is a NaN, or “not a number” (see the section on
float.h in Chapter 15). Otherwise, isnan() yields 0. The argument must be a
real floating-point type. The rule that floating-point types are
promoted to at least double
precision for mathematical calculations does not apply here; the
argument’s properties are determined based on its representation in
its actual semantic type.
double dMax( double a, double b )
{
// NaN overrides all comparison:
if (isnan( a ) ) return a;
if ( isnan( b ) ) return b;
// Anything is greater than -inf:
if ( isinf( a ) && signbit( a ) ) return b;
if ( isinf( b ) && signbit( b ) ) return a;
return ( a > b ? a : b );
}Read now
Unlock full access