You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
continued_fraction uses float division, producing invalid terms for large integers and raising OverflowError #15655
The reproduction uses only Python's standard library; no third-party dependencies are involved.
Expected behavior
continued_fraction(Fraction(2**53 + 3)) should return [9007199254740995], the continued fraction of that integer. Large exact fractions should not fail merely because they exceed floating-point range.
[9007199254740996, -1]
OverflowError: integer division result too large for a float
The first result represents the same integer numerically, but is not the regular continued fraction: the trailing term is negative because the first quotient was rounded upward.
In maths/continued_fraction.py, floor(numerator / denominator) first converts the integer ratio to a float. This loses precision for sufficiently large values and can overflow. Computing the quotient directly with integer floor division (numerator // denominator) preserves exact arithmetic and also handles negative fractions.
I searched existing issues and PRs for continued fraction and continued_fraction; I did not find an existing report of this problem.
Hi, I'd like to take this issue. I'll investigate the division logic in continued_fraction.py, correct the handling of large integers without relying on floating-point conversion, and add tests for large and negative fractions. Could you please assign this issue to me if it's still available? I'll run the relevant tests before submitting a PR.
Activity
Shriraj1901 commentedon Oct 28, 2026
Hi, I'd like to take this issue. I'll investigate the division logic in
continued_fraction.py, correct the handling of large integers without relying on floating-point conversion, and add tests for large and negative fractions. Could you please assign this issue to me if it's still available? I'll run the relevant tests before submitting a PR.dongyikuan919 commentedon Oct 28, 2026
Thanks for offering to investigate and add tests for large and negative fractions! A maintainer can advise on assignment.
AI assistance was used to draft this reply.
Fix continued_fraction for large integers and big fractions (TheAlgor…