bpo-43475: Fix the Python implementation of hash of Decimal NaN (GH-26679)

(cherry picked from commit 9f1c5f6e8a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-06-13 07:05:28 -07:00 committed by GitHub
parent 4becc569a6
commit 128899d8b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 10 deletions

View file

@ -564,6 +564,25 @@ class GeneralFloatCases(unittest.TestCase):
#self.assertTrue(0.0 < pow_op(2.0, -1047) < 1e-315)
#self.assertTrue(0.0 > pow_op(-2.0, -1047) > -1e-315)
def test_hash(self):
for x in range(-30, 30):
self.assertEqual(hash(float(x)), hash(x))
self.assertEqual(hash(float(sys.float_info.max)),
hash(int(sys.float_info.max)))
self.assertEqual(hash(float('inf')), sys.hash_info.inf)
self.assertEqual(hash(float('-inf')), -sys.hash_info.inf)
def test_hash_nan(self):
value = float('nan')
self.assertEqual(hash(value), object.__hash__(value))
class H:
def __hash__(self):
return 42
class F(float, H):
pass
value = F('nan')
self.assertEqual(hash(value), object.__hash__(value))
@requires_setformat
class FormatFunctionsTestCase(unittest.TestCase):