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)
| 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__""" |