Hi,
is it possible to check if a number is NaN or not?
UPDATE: my mistake. fixed the Question.
Hi,
is it possible to check if a number is NaN or not?
UPDATE: my mistake. fixed the Question.
That would depend on what you meant by NILL. Normal integral types don't have a concept of nilliness, unless you mean zero, in which case you'd just use:
if (myInt == 0) { ... }
Floating point types, treat similarly if you mean zero, but they also have the concept of not-a-number (one of the possible results of a dubious calculation). You can either look for a function like isnan
or just use the property that an NaN is not equal to any other number, including itself:
if (myFloat != myFloat) { ... }
Or, if you're talking about pointers of the NULL variety, that's also 0 in C++ so you can use:
if (myPtr == 0) { ... }
Under Linux/gcc, there's isnan(double), conforming to BSD4.3.
C99 provides fpclassify(x) and isnan(x).
(But C++ standards/compilers don't necessarily include C99 functionality.)
There ought to be some way with std::numeric_limit<>... Checking...
Doh. I should have known... This question has been answered before... http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c http://stackoverflow.com/questions/235386/using-nan-in-c http://bytes.com/topic/c/answers/588254-how-check-double-inf-nan