codon
codon copied to clipboard
The Python built-in pow seems to be missing
a = pow(2, 3) throws an error: name 'pow' is not defined, even though pow is a Python built-in.
Here you go:
import math
a = math.pow(2, 3)
print(a)
OK, but what about the Python built-in pow(2, 3, 7)? (math.pow doesn't do the modulo integer exponentiation.) Aren't the Python built-ins supposed to be usable in condon?
Hi @ypfmde, yes pow() should be there -- we'll add it in the next release. Here is a replacement you can use in the meantime:
def pow(base: int, exp: int, mod: int):
if exp < 0:
raise ValueError('negative exponent not supported in pow()')
base %= mod
result = 1
while exp > 0:
if exp & 1:
result = (result * base) % mod
base = (base * base) % mod
exp >>= 1
return result