title: Handling fpu exception on windows
body: <p>I would like to handle fpu exception on windows, something like:</p>
  
  <pre><code>#include &lt;math.h&gt;
  #include &lt;fenv.h&gt;
  #include &lt;stdio.h&gt;
  
  int main()
  {
      double b = 0;
      int raised;
      feclearexcept (FE_ALL_EXCEPT);
      b /= 0;
      raised = fetestexcept (FE_OVERFLOW | FE_INVALID);
      if (raised &amp; FE_OVERFLOW) { printf("over\n");}
      if (raised &amp; FE_INVALID)  { printf("invalid\n");}
  
      return 0;
  }
  </code></pre>
  
  <p>But on windows. I tried reading the MSDN, but the document is not clear at all. I want to do this with Visual Studio compilers, on both x86 and amd64 archs.</p>
  
  <p>I am not interested in translating the exception in C++ - actually, I am not even interested in the FPU exception, only in knowing the FPU state after some computation, like the example above.</p>
  
  <p>== edit ==</p>
  
  <p>Ok, it looks like it is actually much simpler: using _clearfp is enough:</p>
  
  <pre><code>#include &lt;math.h&gt;
  #include &lt;float.h&gt;
  #include &lt;stdio.h&gt;
  
  int main()
  {
      double b = 0;
      int raised;
      raised = _clearfp();
      b /= 0;
      raised = _clearfp();
      if (raised &amp; SW_INVALID)  { printf("invalid\n");}
  
      return 0;
  }
  </code></pre>
  
  <p>Much better than dealing with exceptions, SEH and other non portable stuff :)</p>