MCPcopy Index your code
hub / github.com/python/cpython / fma

Method fma

Lib/_pydecimal.py:1876–1918  ·  view source on GitHub ↗

Fused multiply-add. Returns self*other+third with no rounding of the intermediate product self*other. self and other are multiplied together, with no rounding of the result. The third operand is then added to the result, and a single final rounding is perfo

(self, other, third, context=None)

Source from the content-addressed store, hash-verified

1874 return int(self._rescale(0, ROUND_CEILING))
1875
1876 def fma(self, other, third, context=None):
1877 """Fused multiply-add.
1878
1879 Returns self*other+third with no rounding of the intermediate
1880 product self*other.
1881
1882 self and other are multiplied together, with no rounding of
1883 the result. The third operand is then added to the result,
1884 and a single final rounding is performed.
1885 """
1886
1887 other = _convert_other(other, raiseit=True)
1888 third = _convert_other(third, raiseit=True)
1889
1890 # compute product; raise InvalidOperation if either operand is
1891 # a signaling NaN or if the product is zero times infinity.
1892 if self._is_special or other._is_special:
1893 if context is None:
1894 context = getcontext()
1895 if self._exp == 'N':
1896 return context._raise_error(InvalidOperation, 'sNaN', self)
1897 if other._exp == 'N':
1898 return context._raise_error(InvalidOperation, 'sNaN', other)
1899 if self._exp == 'n':
1900 product = self
1901 elif other._exp == 'n':
1902 product = other
1903 elif self._exp == 'F':
1904 if not other:
1905 return context._raise_error(InvalidOperation,
1906 'INF * 0 in fma')
1907 product = _SignedInfinity[self._sign ^ other._sign]
1908 elif other._exp == 'F':
1909 if not self:
1910 return context._raise_error(InvalidOperation,
1911 '0 * INF in fma')
1912 product = _SignedInfinity[self._sign ^ other._sign]
1913 else:
1914 product = _dec_from_triple(self._sign ^ other._sign,
1915 str(int(self._int) * int(other._int)),
1916 self._exp + other._exp)
1917
1918 return product.__add__(third, context)
1919
1920 def _power_modulo(self, other, modulo, context=None):
1921 """Three argument version of __pow__"""

Callers 11

test_none_argsMethod · 0.95
fmaMethod · 0.45
test_named_parametersMethod · 0.45
test_implicit_contextMethod · 0.45
test_fma_nan_resultsMethod · 0.45
test_fma_infinitiesMethod · 0.45
test_fma_zero_resultMethod · 0.45
test_fma_overflowMethod · 0.45
test_fma_single_roundMethod · 0.45
test_randomMethod · 0.45

Calls 6

_convert_otherFunction · 0.85
getcontextFunction · 0.85
_dec_from_tripleFunction · 0.85
strFunction · 0.85
_raise_errorMethod · 0.80
__add__Method · 0.45

Tested by 10

test_none_argsMethod · 0.76
test_named_parametersMethod · 0.36
test_implicit_contextMethod · 0.36
test_fma_nan_resultsMethod · 0.36
test_fma_infinitiesMethod · 0.36
test_fma_zero_resultMethod · 0.36
test_fma_overflowMethod · 0.36
test_fma_single_roundMethod · 0.36
test_randomMethod · 0.36