I have tried all of my normal tricks for detecting odd numbers (NaN, QNaN,etc) and I can't seem to detect -1.#IND. Any help would be greatly appreciated.
Asked
Active
Viewed 1,514 times
1
-
2possible duplicate of [Checking if a double (or float) is nan in C++](http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c) – Alok Save Mar 12 '12 at 14:04
-
Also, Note that answer by @Cheers and hth. - Alf is the correct one in the marked duplicate. – Alok Save Mar 12 '12 at 14:04
-
Thanks - we can close this one then. – fbl Mar 12 '12 at 15:45
3 Answers
0
Have you tried comparing the number to itself:
if ( x != x )
assert(!"nan");
or simply
assert(x==x);
What are your normal tricks?
Also, odd numbers are 1,3,5,..., as in, the opposite of even. You're talking about NaN's I assume.

Luchian Grigore
- 253,575
- 64
- 457
- 625
-
1I have tried comparing it to itself... works for NaN, QNan, and INF... not IND... – fbl Mar 12 '12 at 14:05
-
0
union _IEEESingle
{
float Float;
struct
{
unsigned int Frac : 23;
unsigned int Exp : 8;
unsigned int Sign : 1;
} IEEE;
};
bool isQnan(float in)
{
return(reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1 &&
reinterpret_cast<_IEEESingle*>(&in)->IEEE.Frac);
}

Ben Cain
- 1
- 1