# Inexact numbers as keys in Association?

Can someone explain me how Mathematica's Associations behave with inexact numbers as keys:

<| 0.22499999999999964 -> a |> [0.22499999999999965]

and

<| 0.22499999999999964 -> a |> [0.22499999999999961]

both give the value a, whereas

<| 0.22499999999999964 -> a |> [0.22499999999999966] gives Missing as an answer.
• Looks like this thing, but with associations. Why do you need to use inexact numbers as keys? – J. M.'s torpor Mar 31 '19 at 13:50
• "Can someone explain me how Mathematica's Associations behave [...]?" They behave badly. Don't do that. – Henrik Schumacher Mar 31 '19 at 13:51
• Association is the name of the function in Mathematica, so I am not sure what was productive about the edit I just rolled back. – J. M.'s torpor Apr 1 '19 at 6:22

Lookups with inexact numbers behave like other lookups: they use hashing. We can check that the results are consistent with what Hash does.

vals = {0.22499999999999961, 0.22499999999999964,
0.22499999999999965, 0.22499999999999966};
Hash /@ vals

(* Out[11]= {1879126079618645156, 1879126079618645156, \
1879126079618645156, 5861724109654749116} *)

When hashing approximate values, there are going to be sharp boundaries (discontinuities, in effect). This is a tradeoff between having "very" close neighbors hash to the same value, and maintaining transitivity.