Obtains a classification of a real floating-point number #include <math.h> int fpclassify ( x ); The fpclassify( ) macro determines whether its argument is a normal floating-point number, or one of several special categories of values, including NaN (not a number), infinity, subnormal floating-point values, zero, and possibly other implementation-specific categories. To determine what category the argument belongs to, compare the return value of fpclassify( ) with the values of the following number classification macros, defined in math.h:
These five macros expand to distinct integer values. Exampledouble minimum( double a, double b ) { register int aclass = fpclassify( a ); register int bclass = fpclassify( b ); if ( aclass == FP_NAN || bclass == FP_NAN ) return NAN; if ( aclass == FP_INFINITE ) // -Inf is less than anything; return ( signbit( a ) ? a : b ); // +inf is greater than anything. if ( bclass == FP_INFINITE ) return ( signbit( b ) ? b : a ); return ( a < b ? a : b ); } See Alsoisfinite( ), isinf( ), isnan( ), isnormal( ), signbit( ) |