You can check if your implementation has:
#include <math.h> #ifdef NAN #endif #ifdef INFINITY #endif
The existence of INFINITY guaranteed by C99 (or at least by the last draft), and "expands to a constant expression of type float representing positive or unsigned infinity, if any; else to a positive constant of type float that overflows during translation."
NAN may or may not be defined, and "is defined if and only if the implementation supports silent NaNs for the float type. It expands to a constant expression of the float type, which is a calm NaN."
Note that if you compare floating point values and do:
a = NAN;
even then,
a == NAN;
is false. One way to check NaN:
#include <math.h> if (isnan(a)) { ... }
You can also do: a != a to check if a NaN.
C99 also has isfinite() , isinf() , isnormal() and signbit() macros in isfinite()
C99 also has NAN features:
#include <math.h> double nan(const char *tagp); float nanf(const char *tagp); long double nanl(ocnst char *tagp);
(Ref: n1256).
Alok Singhal Dec 17 '09 at 19:15 2009-12-17 19:15
source share