INNER CODE UNIT · Python
quot
herumi/mcl · misc/mul-approx.py:77
def quot(self, x):
(x0, x1) = self.getTop(x)
a = x.bit_length()
s= 2*self.d -(a - self.l + 1)
return (x0 * self.p0) >> s
def check(self, x):
(x0, x1) = self.getTop(x)
a = x.bit_length()
(Q, R) = divmod(x, self.p)
S = 1<<(2*self.d - (a - self.l + 1))
(Q2, R2) = divmod(x0 * self.p0, S)
lhs = S * self.p * (Q - Q2)
rhs = S * x1 + self.p1 * x0 - S * R + self.p * R2
if Q == Q2 or Q == Q2 + 1:
return
if Q != Q2:
print('rare case')