isnan


isnan

Tests whether a given floating-point value is "not a number"

 #include <math.h> int isnan ( float x  ); int isnan ( double x  ); int isnan ( long double x  ); 

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.

Example

 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 ); } 

See Also

fpclassify( ), isfinite( ), isinf( ), isnormal( ), signbit( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net