mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-10 13:40:16 +00:00
fix some error.
This commit is contained in:
parent
1db1197670
commit
df33996473
@ -101,6 +101,7 @@ def ulong_divmodi(a: list, b: int):
|
|||||||
|
|
||||||
|
|
||||||
def ulong_divmod(a: list, b: list):
|
def ulong_divmod(a: list, b: list):
|
||||||
|
|
||||||
if ulong_cmp(a, b) < 0:
|
if ulong_cmp(a, b) < 0:
|
||||||
return [0], a
|
return [0], a
|
||||||
|
|
||||||
@ -109,20 +110,26 @@ def ulong_divmod(a: list, b: list):
|
|||||||
r, _ = ulong_fromint(r)
|
r, _ = ulong_fromint(r)
|
||||||
return q, r
|
return q, r
|
||||||
|
|
||||||
low = 0
|
max = (len(a) - len(b)) * PyLong_SHIFT + \
|
||||||
high = (1 << 32) - 1
|
(a[-1].bit_length() - b[-1].bit_length())
|
||||||
while low < high:
|
|
||||||
mid = (low + high + 1) // 2
|
low = [0]
|
||||||
temp = [mid]
|
|
||||||
if ulong_cmp(a, ulong_mul(b, temp)) >= 0:
|
high = (max // PyLong_SHIFT) * [0] + \
|
||||||
|
[(2**(max % PyLong_SHIFT)) & PyLong_MASK]
|
||||||
|
|
||||||
|
while ulong_cmp(low, high) < 0:
|
||||||
|
ulong_inc_(high)
|
||||||
|
mid, r = ulong_divmodi(ulong_add(low, high), 2)
|
||||||
|
if ulong_cmp(a, ulong_mul(b, mid)) >= 0:
|
||||||
low = mid
|
low = mid
|
||||||
else:
|
else:
|
||||||
high = mid - 1
|
high = ulong_sub(mid, [1])
|
||||||
|
|
||||||
q = [0] * (len(a) - len(b) + 1)
|
q = [0] * (len(a) - len(b) + 1)
|
||||||
while ulong_cmp(a, ulong_mul(b, [low])) >= 0:
|
while ulong_cmp(a, ulong_mul(b, low)) >= 0:
|
||||||
q = ulong_add(q, [low])
|
q = ulong_add(q, low)
|
||||||
a = ulong_sub(a, ulong_mul(b, [low]))
|
a = ulong_sub(a, ulong_mul(b, low))
|
||||||
return q, a
|
return q, a
|
||||||
|
|
||||||
def ulong_floordivi(a: list, b: int):
|
def ulong_floordivi(a: list, b: int):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user