-
Notifications
You must be signed in to change notification settings - Fork 10
Description
The documentation for Expressions states often:
Note that when comparing Quil expressions, any embedded NaNs are treated as equal to other NaNs, not unequal, in contravention of the IEEE 754 spec [sic]1
The PartialEq implementation for Expression indeed considers two Numbers equal if, for example, their real and imaginary parts are both NaN; however, the Hash implementation hashes the bit patterns of those NaNs, so if they are different NaNs, for example, quiet vs signaling forms, they will hash to different values.
This is a problem because a valid Hash implementation requires that
We could instead use ordered_float or adjust our implementation to similarly treat all NaNs as a single specific value, though as those docs state, it has implications for interning: we'll lose semantic information about different NaN values.
Note that this is related to #457. We should fix this, and doing so will impact Expression simplification, and the solution may depend on how we want to simplify expressions involving floating point operations.
Footnotes
-
To be pedantic, IEEE 754 specifies that
NaNcomparisons are unordered, not unequal. ↩