Small floats hash to the same value

Description

(= (hash -0.32553251) (hash -0.0000032553251)) ; true

It seems that Java ^ the high and low part for Long.hashCode.

Perhaps we could just Float64Array with one element and assign the JS number. Then we could get the low and high part as 32 bit values and then ^ them.

Environment

None

Activity

Show:

David NolenJanuary 22, 2024 at 3:16 PM

JavaScript has Number.isInteger (as well as Number.isSafeInteger) which is almost a decade old now in terms of support. We could use this to branch to a different hashing strategy.

David NolenJanuary 22, 2024 at 3:07 PM

Clojure uses Double.hashCode for doubles. See https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/Double.java#L1184-L1186. The double is converted to Long bits and then Long.hashCode is invoked.

Fixed

Details

Assignee

Reporter

Priority

Created January 22, 2024 at 3:03 PM
Updated January 22, 2024 at 10:17 PM
Resolved January 22, 2024 at 10:16 PM