Using Floating Point Numbers as Hash Keys (2017)
Postedabout 1 month agoActive25 days ago
readafterwrite.wordpress.comTech Discussionstory
informativeneutral
Debate
20/100
HashingFloating Point NumbersData Structures
Key topics
Hashing
Floating Point Numbers
Data Structures
Discussion Activity
Light discussionFirst comment
6d
Peak period
4
132-144h
Avg / period
4
Key moments
- 01Story posted
Dec 3, 2025 at 10:09 AM EST
about 1 month ago
Step 01 - 02First comment
Dec 9, 2025 at 2:09 AM EST
6d after posting
Step 02 - 03Peak activity
4 comments in 132-144h
Hottest window of the conversation
Step 03 - 04Latest activity
Dec 9, 2025 at 8:13 AM EST
25 days ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 46135349Type: storyLast synced: 12/9/2025, 10:25:22 AM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
AFAICT the pre-hash values come from this method [0] which returns an integer which is a 1:1 representation of the float bytes except that NaNs are all collapsed to one canonical form. So at least at this phase, it doesn't quantize any virtually-equal floats together.
Skimming an implementation of HashMap [1], I didn't notice any obvious "do something special for Floats" code.
[0] https://docs.oracle.com/en/java/javase/17/docs/api/java.base...
[1] https://github.com/openjdk/jdk/blob/master/src/java.base/sha...
> If we continue in this manner we see that all all numbers must have the same hash value h regardless of the choice of ε. The idea of approximate comparison is unfortunately hard to reconcile with the non-approximate nature of hash functions.
I think there is at least one non-sequitur in there? The only thing you prove is that directly modeling hash keys on top of that notion of equality is not useful / the model is weak.
(The license of this comment forbids it from being used as support in favor of floats as hash keys)