Skip to content

complex: Fix hash function to work correctly #1123

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

Merged
merged 1 commit into from
Jul 10, 2019

Conversation

corona10
Copy link
Contributor

@corona10 corona10 commented Jul 9, 2019

Currently, hash(3.1-4.2j) or hash(3.1+4.2j) is crashed due to
overflow error on RustPython.

This patch will fix this issue.

@corona10 corona10 force-pushed the fix_complex_hash branch from b240d02 to 3078468 Compare July 9, 2019 17:02
Currently, hash(3.1-4.2j) or hash(3.1+4.2j) is crashed due to
overflow error on RustPython.

This patch will fix this issue.
@corona10
Copy link
Contributor Author

@silmeth I've updated the PR. PTAL

@@ -254,7 +255,7 @@ impl PyComplex {
fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash {
let re_hash = pyhash::hash_float(self.value.re);
let im_hash = pyhash::hash_float(self.value.im);

re_hash + im_hash * pyhash::IMAG
let ret = Wrapping(re_hash) + Wrapping(im_hash) * Wrapping(pyhash::IMAG);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting stuff, this wrapping! Thanks!

@windelbouwman windelbouwman merged commit dd20263 into RustPython:master Jul 10, 2019
@corona10 corona10 deleted the fix_complex_hash branch July 11, 2019 00:02
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.

4 participants