title: Detecting a negative 0 stored as a double in C++
body: <p>I am doing some mathematical calculations (trying to convert Matlab code into C++, using VS2010) and I need to be able to tell if at some point I get a negative 0. </p>
  
  <p>According to the IEEE standard -0/+0 differ only in the sign bit (the rest are 0). </p>
  
  <p>I have used the following piece of code (<a href="https://stackoverflow.com/questions/1723575">post</a>) to interpret my double as a unsigned char </p>
  
  <pre><code>double f = -5;
      unsigned char *c = reinterpret_cast&lt;unsigned char *&gt;(&amp;f);
      for(int i=(sizeof(double)-1); i&gt;=0; i--){
          printf("%02X", c[i]);
     }
  </code></pre>
  
  <p>Trying it with 5/-5 I get the expected result:</p>
  
  <pre><code>C014000000000000 (-5)
  4014000000000000 (5)
  </code></pre>
  
  <p>But when I try it with 0/-0 I get only zeros in both case. VS2010 states that they are IEEE compliant (<a href="https://stackoverflow.com/questions/1723575">msdn</a>) so I'm not sure which part of it I'm not getting. </p>
  
  <p>If 0/-0 are indeed stored in the memory in the exact same way, there is no way I can tell them apart if I need to so I should stop wasting my time :) Right?</p>