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

Method __pow__

Lib/_pydecimal.py:2250–2464  ·  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

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

Tested by

no test coverage detected