diff options
author | Thomas Wouters <thomas@python.org> | 2007-09-20 18:22:40 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2007-09-20 18:22:40 (GMT) |
commit | 8ce81f767a48e9e645c523137c7f83e49f79f986 (patch) | |
tree | 68e5fa3f61af5f75d43de717a0c997db77dd2910 /Lib/decimal.py | |
parent | 7ce29ca41cd2c41ac7a5981d182f8db25c2af977 (diff) | |
download | cpython-8ce81f767a48e9e645c523137c7f83e49f79f986.zip cpython-8ce81f767a48e9e645c523137c7f83e49f79f986.tar.gz cpython-8ce81f767a48e9e645c523137c7f83e49f79f986.tar.bz2 |
Merged revisions 58211-58220 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58211 | facundo.batista | 2007-09-19 19:53:25 +0200 (Wed, 19 Sep 2007) | 4 lines
Issue #1772851. Optimization of __hash__ to behave better for big big
numbers.
........
r58216 | raymond.hettinger | 2007-09-20 05:03:43 +0200 (Thu, 20 Sep 2007) | 1 line
Fit nits
........
r58217 | georg.brandl | 2007-09-20 10:44:59 +0200 (Thu, 20 Sep 2007) | 2 lines
alternate -> alternative.
........
r58218 | georg.brandl | 2007-09-20 18:06:07 +0200 (Thu, 20 Sep 2007) | 2 lines
Patch #1541463: optimize performance of cgi.FieldStorage operations.
........
r58219 | georg.brandl | 2007-09-20 18:45:27 +0200 (Thu, 20 Sep 2007) | 2 lines
#1176: document that string methods don't take keyword args.
........
r58220 | thomas.wouters | 2007-09-20 19:35:10 +0200 (Thu, 20 Sep 2007) | 4 lines
Try harder to stay within the 79-column limit. There's still two places that go (way) over, but those are harder to fix without suffering in readability.
........
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index d7bd127..ffe6e9e 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -786,10 +786,17 @@ class Decimal(object): if self._isnan(): raise TypeError('Cannot hash a NaN value.') return hash(str(self)) - i = int(self) - if self == Decimal(i): - return hash(i) - assert self.__bool__() # '-0' handled by integer case + if not self: + return 0 + if self._isinteger(): + op = _WorkRep(self.to_integral_value()) + # to make computation feasible for Decimals with large + # exponent, we use the fact that hash(n) == hash(m) for + # any two nonzero integers n and m such that (i) n and m + # have the same sign, and (ii) n is congruent to m modulo + # 2**64-1. So we can replace hash((-1)**s*c*10**e) with + # hash((-1)**s*c*pow(10, e, 2**64-1). + return hash((-1)**op.sign*op.int*pow(10, op.exp, 2**64-1)) return hash(str(self.normalize())) def as_tuple(self): |