title: Hashing floating point values
body: <p>Recently, I was curious how hash algorithms for floating points worked, so I looked at the source code for <code>boost::hash_value</code>.  It turns out to be <a href="http://www.boost.org/doc/libs/1_46_1/boost/functional/hash/detail/hash_float_generic.hpp" rel="noreferrer">fairly complicated</a>.  The actual implementation loops over each digit in the radix and accumulates a hash value.  Compared to the integer hash functions, it's much more involved. </p>
  
  <p>My question is: why should a floating-point hash algorithm be any more complicated?  Why not just hash the binary representation of the floating point value as if it was an integer?</p>
  
  <p>Like:</p>
  
  <pre><code>std::size_t hash_value(float f)
  {
    return hash_value(*(reinterpret_cast&lt;int*&gt;(&amp;f)));
  }
  </code></pre>
  
  <p>I realize that <code>float</code> is not guaranteed to be the same size as <code>int</code> on all systems, but that sort of thing could be handled with a few template meta-programs to deduce an integral type that is the same size as <code>float</code>.  So what is the advantage of introducing an entirely different hash function that specifically operates on floating point types?</p>