Three argument version of __pow__
(self, other, modulo, context=None)
| 1918 | return product.__add__(third, context) |
| 1919 | |
| 1920 | def _power_modulo(self, other, modulo, context=None): |
| 1921 | """Three argument version of __pow__""" |
| 1922 | |
| 1923 | other = _convert_other(other) |
| 1924 | if other is NotImplemented: |
| 1925 | return other |
| 1926 | modulo = _convert_other(modulo) |
| 1927 | if modulo is NotImplemented: |
| 1928 | return modulo |
| 1929 | |
| 1930 | if context is None: |
| 1931 | context = getcontext() |
| 1932 | |
| 1933 | # deal with NaNs: if there are any sNaNs then first one wins, |
| 1934 | # (i.e. behaviour for NaNs is identical to that of fma) |
| 1935 | self_is_nan = self._isnan() |
| 1936 | other_is_nan = other._isnan() |
| 1937 | modulo_is_nan = modulo._isnan() |
| 1938 | if self_is_nan or other_is_nan or modulo_is_nan: |
| 1939 | if self_is_nan == 2: |
| 1940 | return context._raise_error(InvalidOperation, 'sNaN', |
| 1941 | self) |
| 1942 | if other_is_nan == 2: |
| 1943 | return context._raise_error(InvalidOperation, 'sNaN', |
| 1944 | other) |
| 1945 | if modulo_is_nan == 2: |
| 1946 | return context._raise_error(InvalidOperation, 'sNaN', |
| 1947 | modulo) |
| 1948 | if self_is_nan: |
| 1949 | return self._fix_nan(context) |
| 1950 | if other_is_nan: |
| 1951 | return other._fix_nan(context) |
| 1952 | return modulo._fix_nan(context) |
| 1953 | |
| 1954 | # check inputs: we apply same restrictions as Python's pow() |
| 1955 | if not (self._isinteger() and |
| 1956 | other._isinteger() and |
| 1957 | modulo._isinteger()): |
| 1958 | return context._raise_error(InvalidOperation, |
| 1959 | 'pow() 3rd argument not allowed ' |
| 1960 | 'unless all arguments are integers') |
| 1961 | if other < 0: |
| 1962 | return context._raise_error(InvalidOperation, |
| 1963 | 'pow() 2nd argument cannot be ' |
| 1964 | 'negative when 3rd argument specified') |
| 1965 | if not modulo: |
| 1966 | return context._raise_error(InvalidOperation, |
| 1967 | 'pow() 3rd argument cannot be 0') |
| 1968 | |
| 1969 | # additional restriction for decimal: the modulus must be less |
| 1970 | # than 10**prec in absolute value |
| 1971 | if modulo.adjusted() >= context.prec: |
| 1972 | return context._raise_error(InvalidOperation, |
| 1973 | 'insufficient precision: pow() 3rd ' |
| 1974 | 'argument must not have more than ' |
| 1975 | 'precision digits') |
| 1976 | |
| 1977 | # define 0**0 == NaN, for consistency with two-argument pow |
no test coverage detected