-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
float rounding mode affects integer hash function #8910
Comments
The low bits of |
Yes, we could do that too. It won't matter so much because the hash function ends up using all bits of the integer anyway. |
You can create examples where rounding affects all the bits, so this doesn't seem like a solution. |
If |
Perhaps your example is incomplete – when I do the same thing, no error occurs. So it's a bit hard to tell what exactly the issue is that you're talking about here. |
Hmm, that's interesting. Try this:
|
These give the same hash for me: julia> with_rounding(Float64, RoundToZero) do
hash(:normal, Uint(0))
end
0xfaf37cd4f0c6cde6
julia> hash(:normal, Uint(0))
0xfaf37cd4f0c6cde6 |
Try a different rounding mode? |
More data:
|
It's pretty jarring that this depends on floating-point rounding modes. I really think that the whole rounding mode business is completely unusable. julia> with_rounding(Float64, RoundNearest) do
hash(:normal, Uint(0))
end
0xbea927fdf832243d
julia> with_rounding(Float64, RoundDown) do
hash(:normal, Uint(0))
end
0xfaf37cd4f0c6cde6
julia> with_rounding(Float64, RoundUp) do
hash(:normal, Uint(0))
end
0xbea927fdf832243d |
What do you mean by "this"? The hash function? That's the whole point of this issue. Interestingly it looks like you were somehow already in RoundDown or RoundToZero mode. I wonder if some library set that? |
Yes, that hashing of totally floating-point-unrelated things depends on rounding mode. Of course, that's the "clever trick" that allows our hashing to be fast and depend on value, but it's a weird side effect. That is odd – we should certainly always be in a standard rounding mode. I've got to try to get some sleep. |
We've now deprecated changing the rounding mode (#27166), so this is no longer an issue. |
I found this pretty funny:
Naturally, due to this:
Maybe in the
float64(x)
conversion we should mask out the low bits ofx
to make it independent of rounding mode?The text was updated successfully, but these errors were encountered: