MCPcopy Index your code
hub / github.com/python/cpython / __pow__

Method __pow__

Lib/_pydecimal.py:2253–2467  ·  view source on GitHub ↗

Return self ** other [ % modulo]. With two arguments, compute self**other. With three arguments, compute (self**other) % modulo. For the three argument form, the following restrictions on the arguments hold: - all three arguments must be integral

(self, other, modulo=None, context=None)

Source from the content-addressed store, hash-verified

2251 return _dec_from_triple(0, str_xc+'0'*zeros, xe-zeros)
2252
2253 def __pow__(self, other, modulo=None, context=None):
2254 """Return self ** other [ % modulo].
2255
2256 With two arguments, compute self**other.
2257
2258 With three arguments, compute (self**other) % modulo. For the
2259 three argument form, the following restrictions on the
2260 arguments hold:
2261
2262 - all three arguments must be integral
2263 - other must be nonnegative
2264 - either self or other (or both) must be nonzero
2265 - modulo must be nonzero and must have at most p digits,
2266 where p is the context precision.
2267
2268 If any of these restrictions is violated the InvalidOperation
2269 flag is raised.
2270
2271 The result of pow(self, other, modulo) is identical to the
2272 result that would be obtained by computing (self**other) %
2273 modulo with unbounded precision, but is computed more
2274 efficiently. It is always exact.
2275 """
2276
2277 if modulo is not None:
2278 return self._power_modulo(other, modulo, context)
2279
2280 other = _convert_other(other)
2281 if other is NotImplemented:
2282 return other
2283
2284 if context is None:
2285 context = getcontext()
2286
2287 # either argument is a NaN => result is NaN
2288 ans = self._check_nans(other, context)
2289 if ans:
2290 return ans
2291
2292 # 0**0 = NaN (!), x**0 = 1 for nonzero x (including +/-Infinity)
2293 if not other:
2294 if not self:
2295 return context._raise_error(InvalidOperation, '0 ** 0')
2296 else:
2297 return _One
2298
2299 # result has sign 1 iff self._sign is 1 and other is an odd integer
2300 result_sign = 0
2301 if self._sign == 1:
2302 if other._isinteger():
2303 if not other._iseven():
2304 result_sign = 1
2305 else:
2306 # -ve**noninteger = NaN
2307 # (-0)**noninteger = 0**noninteger
2308 if self:
2309 return context._raise_error(InvalidOperation,
2310 'x ** y with x negative and y not an integer')

Callers 2

__rpow__Method · 0.45
powerMethod · 0.45

Calls 15

_power_moduloMethod · 0.95
_check_nansMethod · 0.95
copy_negateMethod · 0.95
_isinfinityMethod · 0.95
adjustedMethod · 0.95
_log10_exp_boundMethod · 0.95
_power_exactMethod · 0.95
_convert_otherFunction · 0.85
getcontextFunction · 0.85
_dec_from_tripleFunction · 0.85
strFunction · 0.85
_WorkRepClass · 0.85

Tested by

no test coverage detected