Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upNaN when hashed should have a random hash value #4510
Comments
This comment has been minimized.
This comment has been minimized.
|
I believe this is exactly addressing the problem that came up. Thanks for pointing it out! I'm happy to follow Russ' lead here. |
This comment has been minimized.
This comment has been minimized.
|
I... am not sure about this! At least let's discuss it. I am trying to remember what precisely we concluded when discussing this after a recent meeting. @pcwalton ? |
This comment has been minimized.
This comment has been minimized.
|
I am going to close this, since I believe the problem is adequately and better addressed by #5283. |
nikomatsakis
closed this
Mar 10, 2013
graydon
reopened this
Mar 11, 2013
This comment has been minimized.
This comment has been minimized.
|
No float-keyed hashtables? |
This comment has been minimized.
This comment has been minimized.
|
@graydon: I think there are ways to work around it, like implementing |
This comment has been minimized.
This comment has been minimized.
|
The underlying issue isn't the equality, it's the hashing itself. It's worth reading the linked article in detail if you haven't yet -- the behavior it describes is intended to maintain the operational invariants of a map. |
This comment has been minimized.
This comment has been minimized.
|
@graydon: The hashing isn't the direct cause of the issue though, |
This comment has been minimized.
This comment has been minimized.
|
@graydon TotalOrd would have a defined ordering and equality for NaN (just as e.g. Java does; check out the rules for Double.equals(), |
This comment has been minimized.
This comment has been minimized.
|
Note that there is no need to fail dynamically when a NaN is encountered. The behavior of TotalOrd (or just Ord, as pcwalton suggested) is just different from the behavior of partial-comparisons (i.e., the |
This comment has been minimized.
This comment has been minimized.
|
(Not that the situations in Java and Racket are directly analogous either. Well, Java basically is. Racket somewhat less so, and I don't claim a deep understand of their solution, but @jbclements and I did some experimentation and found that there is some special treatment around NaN to deal with these inconsistencies.) |
This comment has been minimized.
This comment has been minimized.
|
Ok, so after some discussion I'm reasonably OK with closing this, but I'll make notes here:
This matches the precedent of other languages and I think the intent of the IEEE committee in adding |
graydon
closed this
Mar 12, 2013
This comment has been minimized.
This comment has been minimized.
|
Just to add something I wrote on IRC: my one concern with using conditions is that the method used to hash/compare NaN should really be associated with the data structure, but conditions are dynamically scoped, so making things customizable via conditions opens the door to data structure incoherence. |
dgryski commentedJan 16, 2013
http://research.swtch.com/randhash for more discussion.