Fixes nan

This commit is contained in:
Gyubong Lee committed 2022-07-25 18:07:10 +09:00
1 parent dfc9b6abf4
commit 06056908c9
2 files changed
+5 -3

No files matched your search

-2
View File
@@ -582,8 +582,6 @@ class GeneralFloatCases(unittest.TestCase):
self.assertEqual(hash(float('inf')), sys.hash_info.inf)
self.assertEqual(hash(float('-inf')), -sys.hash_info.inf)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_hash_nan(self):
value = float('nan')
self.assertEqual(hash(value), object.__hash__(value))
+5 -1
View File
@@ -539,7 +539,11 @@ impl Comparable for PyFloat {
impl Hashable for PyFloat {
#[inline]
fn hash(zelf: &crate::Py<Self>, _vm: &VirtualMachine) -> PyResult<hash::PyHash> {
Ok(hash::hash_float(zelf.to_f64()))
if zelf.to_f64().is_nan() {
Ok(zelf.get_id() as hash::PyHash)
} else {
Ok(hash::hash_float(zelf.to_f64()))
}
}
}