Bug 19073 – core.internal.hash should not bitwise hash representations of floating point numbers

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-07-10T14:41:44Z
Last change time
2018-07-27T18:45:41Z
Assigned to
No Owner
Creator
Nathan S.

Comments

Comment #0 by n8sh.secondary — 2018-07-10T14:41:44Z
Currently `hashOf(float)` coalesces all NaNs to have the same hash code when they are hashed directly, but not when they appear as fields of structs or as elements of static arrays or as elements of dynamic arrays. ``` void main() { import core.internal.hash : hashOf; static struct S { float value; } assert(hashOf(float.nan) == hashOf(-float.nan)); // Passes. assert(hashOf(S(float.nan)) == hashOf(S(-float.nan))); // Fails! } ```
Comment #1 by github-bugzilla — 2018-07-27T18:45:40Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/7ebe816eaeb83394558ae5467920eebc9ebde2d9 Fix Issue 19073 - core.internal.hash should not bitwise hash representations of floating point numbers Other minor improvements: - Make hash of static arrays more efficient. - More precise test for when memberwise hashing of structs is necessary (fewer false positives). - Make required return type of `toHash` less brittle. - Special handling for structs wrapping a single element (like std.typecons.Typedef). - Infer scope const for some arrays. - Infer scope const for some structs and unions. - Infer scope const and specialize for final classes that don't override toHash. - Infer scope const and remove unnecessary auto ref for some enums. - As previously, uint and int have same hash. - Slightly clean up bytesHash. https://github.com/dlang/druntime/commit/33659bf5897881537436459229f6c228d6776d89 Merge pull request #2240 from n8sh/core-hash-misc-improvements Fix Issue 19073 - core.internal.hash should not bitwise hash representations of floating point numbers, plus minor improvements and refactoring merged-on-behalf-of: Nathan Sashihara <[email protected]>