Skip to content

Commit 0605690

Browse files
committed
Fixes nan
1 parent dfc9b6a commit 0605690

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/test/test_float.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,6 @@ def test_hash(self):
582582
self.assertEqual(hash(float('inf')), sys.hash_info.inf)
583583
self.assertEqual(hash(float('-inf')), -sys.hash_info.inf)
584584

585-
# TODO: RUSTPYTHON
586-
@unittest.expectedFailure
587585
def test_hash_nan(self):
588586
value = float('nan')
589587
self.assertEqual(hash(value), object.__hash__(value))

vm/src/builtins/float.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,11 @@ impl Comparable for PyFloat {
539539
impl Hashable for PyFloat {
540540
#[inline]
541541
fn hash(zelf: &crate::Py<Self>, _vm: &VirtualMachine) -> PyResult<hash::PyHash> {
542-
Ok(hash::hash_float(zelf.to_f64()))
542+
if zelf.to_f64().is_nan() {
543+
Ok(zelf.get_id() as hash::PyHash)
544+
} else {
545+
Ok(hash::hash_float(zelf.to_f64()))
546+
}
543547
}
544548
}
545549

0 commit comments

Comments
 (0)