diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-04 19:30:01 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-04 19:30:01 (GMT) |
commit | 8b0facf89e4ab62580efbcf74c70f636186f1e08 (patch) | |
tree | 7f12e2ba4e9b6f71d6c198138633fd39c8714223 /Lib/decimal.py | |
parent | 43f827b9fabd616fab6e62db7d5487d040b05179 (diff) | |
download | cpython-8b0facf89e4ab62580efbcf74c70f636186f1e08.zip cpython-8b0facf89e4ab62580efbcf74c70f636186f1e08.tar.gz cpython-8b0facf89e4ab62580efbcf74c70f636186f1e08.tar.bz2 |
Merged revisions 59323-59332 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59324 | georg.brandl | 2007-12-04 17:10:02 +0100 (Tue, 04 Dec 2007) | 3 lines
Add "Python on Unix" document, mostly written for GHOP
by Shriphani Palakodety.
........
r59325 | facundo.batista | 2007-12-04 17:31:53 +0100 (Tue, 04 Dec 2007) | 3 lines
fma speedup by avoiding to create a Context. Thanks Mark Dickinson.
........
r59326 | christian.heimes | 2007-12-04 17:36:20 +0100 (Tue, 04 Dec 2007) | 2 lines
Added warning that make install may overwrite or masquerade the default python binary. Use make altinstall instead.
A native English speaker may want to rephrase the paragraph. ;)
........
r59327 | georg.brandl | 2007-12-04 17:50:28 +0100 (Tue, 04 Dec 2007) | 2 lines
Fix duplicate label and a typo.
........
r59329 | georg.brandl | 2007-12-04 18:46:27 +0100 (Tue, 04 Dec 2007) | 2 lines
Add tutorial and examples to logging docs, from GHOP student "oscar8thegrouch".
........
r59332 | christian.heimes | 2007-12-04 19:43:19 +0100 (Tue, 04 Dec 2007) | 1 line
These optimizations create smaller and a bit faster code on my machine. I've also disabled an optimization that may be dangerous. Intrinsic functions conflict with errno.
........
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 39ce582..7f95768 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1646,24 +1646,39 @@ class Decimal(object): """ other = _convert_other(other, raiseit=True) - third = _convert_other(third, raiseit=True) - - if context is None: - context = getcontext() - - # do self*other in fresh context with no traps and no rounding - mul_context = Context(traps=[], flags=[], - _rounding_decision=NEVER_ROUND) - product = self.__mul__(other, mul_context) - if mul_context.flags[InvalidOperation]: - # reraise in current context - return context._raise_error(InvalidOperation, - 'invalid multiplication in fma', - 1, product) + # compute product; raise InvalidOperation if either operand is + # a signaling NaN or if the product is zero times infinity. + if self._is_special or other._is_special: + if context is None: + context = getcontext() + if self._exp == 'N': + return context._raise_error(InvalidOperation, 'sNaN', + 1, self) + if other._exp == 'N': + return context._raise_error(InvalidOperation, 'sNaN', + 1, other) + if self._exp == 'n': + product = self + elif other._exp == 'n': + product = other + elif self._exp == 'F': + if not other: + return context._raise_error(InvalidOperation, + 'INF * 0 in fma') + product = Infsign[self._sign ^ other._sign] + elif other._exp == 'F': + if not self: + return context._raise_error(InvalidOperation, + '0 * INF in fma') + product = Infsign[self._sign ^ other._sign] + else: + product = _dec_from_triple(self._sign ^ other._sign, + str(int(self._int) * int(other._int)), + self._exp + other._exp) - ans = product.__add__(third, context) - return ans + third = _convert_other(third, raiseit=True) + return product.__add__(third, context) def _power_modulo(self, other, modulo, context=None): """Three argument version of __pow__""" |