mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fixes nan
This commit is contained in:
1 parent
dfc9b6abf4
commit
06056908c9
2 files changed
+5
-3
No files matched your search
Vendored
-2
@@ -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))
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user