fma speedup by avoiding to create a Context. Thanks Mark Dickinson.

This commit is contained in:
Facundo Batista 2007-12-04 16:31:53 +00:00
parent d95a1ee652
commit 58f6f2e0c9

View file

@ -1636,24 +1636,39 @@ class Decimal(object):
""" """
other = _convert_other(other, raiseit=True) other = _convert_other(other, raiseit=True)
third = _convert_other(third, raiseit=True)
# 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: if context is None:
context = getcontext() context = getcontext()
if self._exp == 'N':
# do self*other in fresh context with no traps and no rounding return context._raise_error(InvalidOperation, 'sNaN',
mul_context = Context(traps=[], flags=[], 1, self)
_rounding_decision=NEVER_ROUND) if other._exp == 'N':
product = self.__mul__(other, mul_context) return context._raise_error(InvalidOperation, 'sNaN',
1, other)
if mul_context.flags[InvalidOperation]: if self._exp == 'n':
# reraise in current context product = self
elif other._exp == 'n':
product = other
elif self._exp == 'F':
if not other:
return context._raise_error(InvalidOperation, return context._raise_error(InvalidOperation,
'invalid multiplication in fma', 'INF * 0 in fma')
1, product) 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) third = _convert_other(third, raiseit=True)
return ans return product.__add__(third, context)
def _power_modulo(self, other, modulo, context=None): def _power_modulo(self, other, modulo, context=None):
"""Three argument version of __pow__""" """Three argument version of __pow__"""