Description
Repository commit
6e03a48579ca212a08b36be00378f887dc41a003
Python version (python --version)
Python 3.11.0, macOS
Dependencies version (pip freeze)
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.
Actual behavior
Run from the repository root:
from fractions import Fraction
from maths.continued_fraction import continued_fraction
print(continued_fraction(Fraction(2**53 + 3)))
try:
print(continued_fraction(Fraction(10**400, 3)))
except OverflowError as exc:
print(type(exc).__name__ + ':', exc)Output:
[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.
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…