Issue #7233: A number of two-argument Decimal methods were failing to

accept ints and longs for the second argument.
This commit is contained in:
Mark Dickinson 2009-10-29 12:04:00 +00:00
parent 783b877555
commit 0c67312c5c
3 changed files with 70 additions and 1 deletions

View file

@ -2723,6 +2723,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
@ -2792,6 +2794,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)
@ -3160,6 +3164,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)
@ -3181,6 +3188,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)
@ -3195,6 +3205,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)
@ -3408,6 +3421,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
@ -3432,11 +3447,13 @@ class Decimal(object):
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
@ -3460,6 +3477,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