title: Fastest way to flip the sign of a double / float in C
body: <p>What is the fastest way to flip the sign of a double (or float) in C?</p>
  
  <p>I thought, that accessing the sign bit directly would be the fastest way and found the following:</p>
  
  <pre><code>double a = 5.0;
  *(__int64*)&amp;a |= 0x8000000000000000;
  // a = -5.0
  
  float b = 3.0;
  *(int*)&amp;b |= 0x80000000;
  // b = -3.0
  </code></pre>
  
  <p>However, the above does not work for negative numbers:</p>
  
  <pre><code>double a = -5.0;
  *(__int64*)&amp;a |= 0x8000000000000000;
  // a = -5.0
  </code></pre>