hash is documented to be consistent with = but Util/hasheq returns different hash values for some pairs of numbers that are =
Consequences include incorrect behavior for hash-maps containing keys that are =, but have different hash values:
The only BigInteger values that have inconsistent hash values should be those in the range of a long. BigInteger and BigInt values outside the range of a long already both return BigInteger.hashCode().
All integer values will return consistent hash codes if we add a new case to Numbers.hasheq(Number) for BigIntegers that lie in the range of a long, returning the same hash that such a long value does.
For floating point values, the patch makes their hashes consistent by converting floats to doubles and then hashing.
One alternate approach would be to convert all double values to floats and hash float values only. However, this throws away half of the bits of the double value before hashing, leading to many undesirable hash collisions between different double values.
Add new patch clj-1036-hasheq-for-biginteger-patch-v4.txt dated Aug 8 2013 that handles floating point hashes better. Description will be updated to match.
It is out of scope for Clojure to fix this for Java types Float/Double/BigInteger
Comment made by: vjlf
What about making = always return false for float/double comparisons? It would technically be a breaking change, but only for those who are doing a Bad Thing that doesn't reliably work in the first place.
I think it would be best to work this on a new ticket.