def _pow_mod(space, iv, iw, iz): from rpython.rlib.rarithmetic import mulmod if iw <= 0: if iw == 0: return 1 % iz # != 1, for iz == 1 or iz < 0 raise oefmt( space.w_TypeError, "pow() 2nd argument cannot be negative when 3rd " "argument specified") if iz < 0: try: iz = ovfcheck(-iz) except OverflowError: raise iz_negative = True else: iz_negative = False temp = iv ix = 1 while True: if iw & 1: ix = mulmod(ix, temp, iz) iw >>= 1 # Shift exponent down by 1 bit if iw == 0: break temp = mulmod(temp, temp, iz) if iz_negative and ix > 0: ix -= iz return ix
def int_mulmod(space, a, b, c): return space.newint(mulmod(a, b, c))
def func(a, b, c): return mulmod(a, b, c)