title: Sign of a floating point number
body: <p>Is there an easy way to determine the sign of a floating point number?</p>
  
  <p>I experimented and came up with this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main(int argc, char** argv)
  {
   union
   {
    float f;
    char c[4];
   };
  
   f = -0.0f;
   std::cout &lt;&lt; (c[3] &amp; 0x10000000) &lt;&lt; "\n";
  
   std::cin.ignore();
   std::cin.get();
   return 0;
  }
  </code></pre>
  
  <p>where (c[3] &amp; 0x10000000) gives a value > 0 for a negative number but I think this requires me to make the assumptions that:</p>
  
  <ul>
  <li>The machine's bytes are 8 bits big</li>
  <li>a float point number is 4 bytes big?</li>
  <li>the machine's most significant bit is
  the left-most bit (endianness?)</li>
  </ul>
  
  <p>Please correct me if any of those assumptions are wrong or if I have missed any.</p>