Skip to content

Infinite loop in Burnikel-Ziegler division algorithm in _pylong.py #128709

@Julien-Livet

Description

@Julien-Livet

Bug report

Bug description:

I want to transpose the code in C++ but I discovered a problem in Python code.

Here is the sample test:

a = 561453*2**64 + 13205*2**32 + 1564
b = 1698*2**32 + 721
q = 330*2**32 + 2815252282
r = 414*2**32 + 1722637250
print("a", a)
print("b", b)
print("q", q)
print("r", r)
q_, r_ = int_divmod(a, b)
print("q_", q_)
print("r_", r_)

If I comment lines 435 and 436 for testing:

if a.bit_length() - n <= _DIV_LIMIT:
        return divmod(a, b)

I obtained an infinite loop and I don't understand why.
Is the algorithm work on an existing test?

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions