MCPcopy Index your code
hub / github.com/RustPython/RustPython / fma

Method fma

Lib/_pydecimal.py:1873–1915  ·  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

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

Callers 13

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
dd_mulMethod · 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