Welcome! Please see the About page for a little more info on how this works.

0 votes
in Java Interop by
This is closely related to CLJ-1036, but there was a suggestion to make a new ticket.

The issue is that for a float {{f}} and a double {{d}}, we can have {{(= f d)}} but not {{(= (hash f) (hash d))}}, which breaks a fundamental assumption about hash/equality consistency and leads to weirdness like this (from Immo Heikkinen's email to the Clojure mailing list):


(= (float 0.5) (double 0.5))
=> true
(= #{(float 0.5)} #{(double 0.5)})
=> true
(= {:a (float 0.5)} {:a (double 0.5)})
=> true
(= #{{:a (float 0.5)}} #{{:a (double 0.5)}})
=> false


One way to resolve this would be to tweak the hashing of floats and/or doubles, but that suggestion has apparently been rejected.

An alternative would be to modify {{=}} so that it never returns true for float/double comparisons. One should never compare floats with doubles using {{=}} anyway, so such a change should have minimal impact beyond restoring hash/equality consistency.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1649 (reported by alex+import)
...