Issue #7279: Make Decimal('nan') hashable. Decimal('snan') remains unhashable.

Also rewrite the Decimal __hash__ method so that it doesn't rely on
float('inf') being valid: float('inf') could raise an exception on
platforms not using IEEE 754 arithmetic.
This commit is contained in:
Mark Dickinson 2010-04-02 10:35:12 +00:00
parent e096e82e82
commit f3eeca16cb
3 changed files with 27 additions and 6 deletions

View file

@ -1274,6 +1274,10 @@ class DecimalUsabilityTest(unittest.TestCase):
def test_hash_method(self):
#just that it's hashable
hash(Decimal(23))
hash(Decimal('Infinity'))
hash(Decimal('-Infinity'))
hash(Decimal('nan123'))
hash(Decimal('-NaN'))
test_values = [Decimal(sign*(2**m + n))
for m in [0, 14, 15, 16, 17, 30, 31,
@ -1308,7 +1312,7 @@ class DecimalUsabilityTest(unittest.TestCase):
#the same hash that to an int
self.assertEqual(hash(Decimal(23)), hash(23))
self.assertRaises(TypeError, hash, Decimal('NaN'))
self.assertRaises(TypeError, hash, Decimal('sNaN'))
self.assertTrue(hash(Decimal('Inf')))
self.assertTrue(hash(Decimal('-Inf')))