title: Catch Nan and Inf in Windows C++
body: <p>I painfully learned today that <strong>Nan</strong> and <strong>Inf</strong> have serious side issues. Did you know for example that sqrtf(NaN) is more than <strong>15 times slower</strong> and sqrtf(-1) is <strong>30 times slower</strong> (!!)  than sqrtf(10.123132) - which is on its own a quite slow, floating point calculation!? You calculate rubbish, need ridiculous amounts of time for it and don't even realize it.</p>
  
  <p>Ok, under Linux you can catch Nan and Inf bugs by throwing an exception when they occur:</p>
  
  <pre><code>#include &lt;fenv.h&gt; 
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
  </code></pre>
  
  <p>How could you achieve that under Windows?</p>
  
  <p>EDIT:
  the Benchmarking code:</p>
  
  <pre><code>float a,b;
  a = 1.0 / 0;   //inf
  a = -10;         //also nice
  long c=0;
  long time = SDL_GetTicks();
  
  for (long i=1;i&lt;=1000000;i++) {
     b=sqrt(a); 
  }
  
  ostringstream Help; Help &lt;&lt; SDL_GetTicks()-time;
  
  //RESULT SHEET
  //sqrt(1): 21ms
  //sqrt(10): 21ms
  //sqrt(10.123): 20ms
  //sqrt(-10);   390ms
  //sqrt(+-NaN): 174ms
  //sqrt(inf):  174
  </code></pre>