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

Method _power_modulo

Lib/_pydecimal.py:1917–2000  ·  view source on GitHub ↗

Three argument version of __pow__

(self, other, modulo, context=None)

Source from the content-addressed store, hash-verified

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

Callers 1

__pow__Method · 0.95

Calls 14

_isnanMethod · 0.95
_fix_nanMethod · 0.95
_isintegerMethod · 0.95
to_integral_valueMethod · 0.95
_convert_otherFunction · 0.85
getcontextFunction · 0.85
_WorkRepClass · 0.85
_dec_from_tripleFunction · 0.85
strFunction · 0.85
_raise_errorMethod · 0.80
adjustedMethod · 0.80
_isevenMethod · 0.80

Tested by

no test coverage detected