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