MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _power_modulo

Method _power_modulo

tools/python-3.11.9-amd64/Lib/_pydecimal.py:1976–2059  ·  view source on GitHub ↗

Three argument version of __pow__

(self, other, modulo, context=None)

Source from the content-addressed store, hash-verified

1974 return product.__add__(third, context)
1975
1976 def _power_modulo(self, other, modulo, context=None):
1977 """Three argument version of __pow__"""
1978
1979 other = _convert_other(other)
1980 if other is NotImplemented:
1981 return other
1982 modulo = _convert_other(modulo)
1983 if modulo is NotImplemented:
1984 return modulo
1985
1986 if context is None:
1987 context = getcontext()
1988
1989 # deal with NaNs: if there are any sNaNs then first one wins,
1990 # (i.e. behaviour for NaNs is identical to that of fma)
1991 self_is_nan = self._isnan()
1992 other_is_nan = other._isnan()
1993 modulo_is_nan = modulo._isnan()
1994 if self_is_nan or other_is_nan or modulo_is_nan:
1995 if self_is_nan == 2:
1996 return context._raise_error(InvalidOperation, 'sNaN',
1997 self)
1998 if other_is_nan == 2:
1999 return context._raise_error(InvalidOperation, 'sNaN',
2000 other)
2001 if modulo_is_nan == 2:
2002 return context._raise_error(InvalidOperation, 'sNaN',
2003 modulo)
2004 if self_is_nan:
2005 return self._fix_nan(context)
2006 if other_is_nan:
2007 return other._fix_nan(context)
2008 return modulo._fix_nan(context)
2009
2010 # check inputs: we apply same restrictions as Python's pow()
2011 if not (self._isinteger() and
2012 other._isinteger() and
2013 modulo._isinteger()):
2014 return context._raise_error(InvalidOperation,
2015 'pow() 3rd argument not allowed '
2016 'unless all arguments are integers')
2017 if other < 0:
2018 return context._raise_error(InvalidOperation,
2019 'pow() 2nd argument cannot be '
2020 'negative when 3rd argument specified')
2021 if not modulo:
2022 return context._raise_error(InvalidOperation,
2023 'pow() 3rd argument cannot be 0')
2024
2025 # additional restriction for decimal: the modulus must be less
2026 # than 10**prec in absolute value
2027 if modulo.adjusted() >= context.prec:
2028 return context._raise_error(InvalidOperation,
2029 'insufficient precision: pow() 3rd '
2030 'argument must not have more than '
2031 'precision digits')
2032
2033 # 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
powFunction · 0.85
_dec_from_tripleFunction · 0.85
strFunction · 0.85
_raise_errorMethod · 0.80
adjustedMethod · 0.80

Tested by

no test coverage detected