Boost C++ Libraries: Ticket #4038: hash_value(float) collision https://svn.boost.org/trac10/ticket/4038 <p> the hash_value function for floats has at least one collision that is rather serious: </p> <p> std::size_t zero = boost::hash_value(0.0f); std::size_t half = boost::hash_value(0.5f); </p> <p> both of these have the same hash value. Why not just use reinterpret_cast &lt;&gt; for this hash function? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4038 Trac 1.4.3 Daniel James Wed, 24 Mar 2010 08:28:31 GMT status changed https://svn.boost.org/trac10/ticket/4038#comment:1 https://svn.boost.org/trac10/ticket/4038#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Because in cross platform development there's no guarantee that two floats with different binary representations will be unequal, and there's no guarantee that the binary representation will be the same size as std::size_t. I do use a binary algorithm on a limited number of platforms, and could for others, but it has to be done carefully and there are more important things to do. </p> Ticket Daniel James Wed, 24 Mar 2010 08:49:02 GMT <link>https://svn.boost.org/trac10/ticket/4038#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4038#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/60805" title="Remove optimization which causes 0.5 to hash to 0. Refs #4038. I have ...">[60805]</a>) Remove optimization which causes 0.5 to hash to 0. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4038" title="#4038: Bugs: hash_value(float) collision (closed: fixed)">#4038</a>. </p> <p> I have an internal requirement the 0 hashes to 0, a better solution might be to remove that, put the optimization back and hash 0 to another value. Or alternatively, use the main combine function instead. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Wed, 31 Mar 2010 21:39:13 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4038#comment:3 https://svn.boost.org/trac10/ticket/4038#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/60980" title="Merge from trunk. - Add `quick_erase` for unordered. ...">[60980]</a>) Merge from trunk. </p> <ul><li>Add <code>quick_erase</code> for unordered. <code>erase_return_void</code> is now deprecated. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3966" title="#3966: Bugs: Rename `erase_return_void` to `quick_erase`. (closed: fixed)">#3966</a> </li><li>Avoid collision between 0 and 0.5. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4038" title="#4038: Bugs: hash_value(float) collision (closed: fixed)">#4038</a> </li></ul> Ticket