mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Issue #7233: Fix Decimal.shift and Decimal.rotate methods for
arguments with more digits than the current context precision. Bug reported by Stefan Krah.
This commit is contained in:
parent
0c67312c5c
commit
6f3900163a
3 changed files with 43 additions and 10 deletions
|
@ -3439,8 +3439,10 @@ class Decimal(object):
|
|||
torot = int(other)
|
||||
rotdig = self._int
|
||||
topad = context.prec - len(rotdig)
|
||||
if topad:
|
||||
if topad > 0:
|
||||
rotdig = '0'*topad + rotdig
|
||||
elif topad < 0:
|
||||
rotdig = rotdig[-topad:]
|
||||
|
||||
# let's rotate!
|
||||
rotated = rotdig[torot:] + rotdig[:torot]
|
||||
|
@ -3493,22 +3495,22 @@ class Decimal(object):
|
|||
|
||||
# get values, pad if necessary
|
||||
torot = int(other)
|
||||
if not torot:
|
||||
return Decimal(self)
|
||||
rotdig = self._int
|
||||
topad = context.prec - len(rotdig)
|
||||
if topad:
|
||||
if topad > 0:
|
||||
rotdig = '0'*topad + rotdig
|
||||
elif topad < 0:
|
||||
rotdig = rotdig[-topad:]
|
||||
|
||||
# let's shift!
|
||||
if torot < 0:
|
||||
rotated = rotdig[:torot]
|
||||
shifted = rotdig[:torot]
|
||||
else:
|
||||
rotated = rotdig + '0'*torot
|
||||
rotated = rotated[-context.prec:]
|
||||
shifted = rotdig + '0'*torot
|
||||
shifted = shifted[-context.prec:]
|
||||
|
||||
return _dec_from_triple(self._sign,
|
||||
rotated.lstrip('0') or '0', self._exp)
|
||||
shifted.lstrip('0') or '0', self._exp)
|
||||
|
||||
# Support for pickling, copy, and deepcopy
|
||||
def __reduce__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue