Opened 13 years ago
Closed 13 years ago
#4038 closed Bugs (fixed)
hash_value(float) collision
Reported by: | Owned by: | Daniel James | |
---|---|---|---|
Milestone: | Boost 1.43.0 | Component: | hash |
Version: | Boost 1.41.0 | Severity: | Problem |
Keywords: | hash_value collision float | Cc: |
Description
the hash_value function for floats has at least one collision that is rather serious:
std::size_t zero = boost::hash_value(0.0f); std::size_t half = boost::hash_value(0.5f);
both of these have the same hash value. Why not just use reinterpret_cast <> for this hash function?
Change History (3)
comment:1 by , 13 years ago
Status: | new → assigned |
---|
comment:2 by , 13 years ago
comment:3 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
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.