summaryrefslogtreecommitdiff
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2007-09-13 18:42:09 +0000
committerFacundo Batista <facundobatista@gmail.com>2007-09-13 18:42:09 +0000
commitbd2fe839db886de6ce9631acd8aa9796b413a565 (patch)
tree46639f8177e11939366dacece1e86bf41456fadf /Lib/decimal.py
parent353750c405c9099d0be69c6af1d17037b38c4ddf (diff)
downloadcpython-git-bd2fe839db886de6ce9631acd8aa9796b413a565.tar.gz
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted to Decimal, just as with all the other two-argument operations. Thanks Mark Dickinson.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 8543e1090a..b2bfc567a4 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -2160,12 +2160,13 @@ class Decimal(object):
end -= 1
return Decimal( (dup._sign, dup._int[:end], exp) )
-
- def quantize(self, exp, rounding=None, context=None):
+ def quantize(self, exp, rounding=None, context=None, watchexp=True):
"""Quantize self so its exponent is the same as that of exp.
Similar to self._rescale(exp._exp) but with error checking.
"""
+ exp = _convert_other(exp, raiseit=True)
+
if context is None:
context = getcontext()
if rounding is None:
@@ -2182,6 +2183,16 @@ class Decimal(object):
return context._raise_error(InvalidOperation,
'quantize with one INF')
+ # if we're not watching exponents, do a simple rescale
+ if not watchexp:
+ ans = self._rescale(exp._exp, rounding)
+ # raise Inexact and Rounded where appropriate
+ if ans._exp > self._exp:
+ context._raise_error(Rounded)
+ if ans != self:
+ context._raise_error(Inexact)
+ return ans
+
# exp._exp should be between Etiny and Emax
if not (context.Etiny() <= exp._exp <= context.Emax):
return context._raise_error(InvalidOperation,