summaryrefslogtreecommitdiff
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-10-29 12:25:07 +0000
committerMark Dickinson <dickinsm@gmail.com>2009-10-29 12:25:07 +0000
commit9050bb28f2d73a1be8d568aea2b2eb9f53b90468 (patch)
treefe9d699d7baf2f5f41971079c117888e097f5718 /Lib/decimal.py
parent00de1bdcfcc9b5d4555c77796c0c8e93944bfb7d (diff)
downloadcpython-git-9050bb28f2d73a1be8d568aea2b2eb9f53b90468.tar.gz
Merged revisions 75947 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r75947 | mark.dickinson | 2009-10-29 12:23:02 +0000 (Thu, 29 Oct 2009) | 20 lines Merged revisions 75943-75945 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75943 | mark.dickinson | 2009-10-29 11:09:09 +0000 (Thu, 29 Oct 2009) | 1 line Fix duplicate test numbers in extra.decTest ........ r75944 | mark.dickinson | 2009-10-29 12:04:00 +0000 (Thu, 29 Oct 2009) | 3 lines Issue #7233: A number of two-argument Decimal methods were failing to accept ints and longs for the second argument. ........ r75945 | mark.dickinson | 2009-10-29 12:11:18 +0000 (Thu, 29 Oct 2009) | 4 lines Issue #7233: Fix Decimal.shift and Decimal.rotate methods for arguments with more digits than the current context precision. Bug reported by Stefan Krah. ........ ................
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index b44c3f51de..3450066d4b 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -2806,6 +2806,8 @@ class Decimal(object):
value. Note that a total ordering is defined for all possible abstract
representations.
"""
+ other = _convert_other(other, raiseit=True)
+
# if one is negative and the other is positive, it's easy
if self._sign and not other._sign:
return _NegativeOne
@@ -2875,6 +2877,8 @@ class Decimal(object):
Like compare_total, but with operand's sign ignored and assumed to be 0.
"""
+ other = _convert_other(other, raiseit=True)
+
s = self.copy_abs()
o = other.copy_abs()
return s.compare_total(o)
@@ -3243,6 +3247,9 @@ class Decimal(object):
"""Applies an 'and' operation between self and other's digits."""
if context is None:
context = getcontext()
+
+ other = _convert_other(other, raiseit=True)
+
if not self._islogical() or not other._islogical():
return context._raise_error(InvalidOperation)
@@ -3264,6 +3271,9 @@ class Decimal(object):
"""Applies an 'or' operation between self and other's digits."""
if context is None:
context = getcontext()
+
+ other = _convert_other(other, raiseit=True)
+
if not self._islogical() or not other._islogical():
return context._raise_error(InvalidOperation)
@@ -3278,6 +3288,9 @@ class Decimal(object):
"""Applies an 'xor' operation between self and other's digits."""
if context is None:
context = getcontext()
+
+ other = _convert_other(other, raiseit=True)
+
if not self._islogical() or not other._islogical():
return context._raise_error(InvalidOperation)
@@ -3491,6 +3504,8 @@ class Decimal(object):
if context is None:
context = getcontext()
+ other = _convert_other(other, raiseit=True)
+
ans = self._check_nans(other, context)
if ans:
return ans
@@ -3507,19 +3522,23 @@ 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]
return _dec_from_triple(self._sign,
rotated.lstrip('0') or '0', self._exp)
- def scaleb (self, other, context=None):
+ def scaleb(self, other, context=None):
"""Returns self operand after adding the second value to its exp."""
if context is None:
context = getcontext()
+ other = _convert_other(other, raiseit=True)
+
ans = self._check_nans(other, context)
if ans:
return ans
@@ -3543,6 +3562,8 @@ class Decimal(object):
if context is None:
context = getcontext()
+ other = _convert_other(other, raiseit=True)
+
ans = self._check_nans(other, context)
if ans:
return ans
@@ -3557,22 +3578,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):