Name
fpclassify
Synopsis
Obtains a classification of a real floating-point number
#include <math.h> intfpclassify
(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:
FP_INFINITE |
FP_NAN |
FP_NORMAL |
FP_SUBNORMAL |
FP_ZERO |
These five macros expand to distinct integer values.
Example
double 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 Also
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.