-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hash(big(pi)) == hash(float64(pi)) && big(pi) != float64(pi). #3385
Comments
Currently we have |
We should probably have a discussion on the dev list about whether it's acceptable to have |
The behavior of
Type dispatch is routine, so we have to assume There may be cases where implementers need to assume There are a couple cases where it is not clear what |
Stefan and I agreed to go ahead with this. One way to look at it is that Strings in different encodings are superficially similar to numbers of different types, but actually quite different since the different encodings are isomorphic --- strings in different encodings can generate the same sequence of |
In particular, it would be pathological to produce unequal results for equal string inputs with different encodings whereas producing unequal results for equal float inputs with different precisions is typical. |
The problem seems to be that
hash(x::FloatingPoint)
callshash64(float64(x))
, implicitly assuming thatFloat64
is the widest possible floating-point type.A lot of the mess here seems to stem from an attempt to make
x == y
implyhash(x) == hash(y)
even ifx
andy
are arbitrarily different types. This seems unworkable to me in the long run, as more numeric types are added. Especially user-defined types. However, the converse should certainly be true:x != y
should implyhash(x) != hash(y)
(except in the extremely unlikely event of a hash collision).The text was updated successfully, but these errors were encountered: