1

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.

fbl
  • 2,840
  • 3
  • 33
  • 41

3 Answers3

3

Try this:

http://www.johndcook.com/IEEE_exceptions_in_cpp.html

JTeagle
  • 2,196
  • 14
  • 15
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
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