Skip to content
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

Refactor hash float #129

Merged
merged 2 commits into from
Apr 8, 2023
Merged

Refactor hash float #129

merged 2 commits into from
Apr 8, 2023

Conversation

jogru0
Copy link

@jogru0 jogru0 commented Apr 8, 2023

Hi!

I noticed that for hashing ordered floats, we normalize NaN to a unique representation, just to later check for .is_nan() in raw_double_bits anyway.

Also, for NotNan, we have this .is_nan() check in raw_double_bits, even though it can never be true due to the NotNan invariant.

So I decided to try to restructure the hashing code a bit. The special cases are now all handled uniformly inside the hash implementations, and raw_double_bits just does the raw bit conversion, without any special handling.

I took care to not change the actual resulting hashes, in case that's relevant for backwards compatibility.

Also, I added a test case for mapping 0 and -0 for NotNan to the same hash, and one for mapping different representations of NaN for OrderedFloat to the same hash.

@mbrubeck mbrubeck merged commit 97a2711 into reem:master Apr 8, 2023
2 checks passed
@mbrubeck
Copy link
Collaborator

mbrubeck commented Apr 8, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants