Skip to content

complex: Fix hash function to work correctly#1123

Merged
windelbouwman merged 1 commit into
RustPython:masterfrom
corona10:fix_complex_hash
Jul 10, 2019
Merged

complex: Fix hash function to work correctly#1123
windelbouwman merged 1 commit into
RustPython:masterfrom
corona10:fix_complex_hash

Conversation

@corona10
Copy link
Copy Markdown
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
Comment thread tests/snippets/builtin_complex.py Outdated
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
Copy Markdown
Contributor Author

@silmeth I've updated the PR. PTAL

Comment thread vm/src/obj/objcomplex.rs
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
Copy Markdown
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