Continued Fraction Calculator
Convert any decimal or fraction to its continued fraction [a₀; a₁, a₂, …] with full convergents table, error bounds, and step-by-step Euclidean algorithm.
Enter a decimal or fraction above to compute its continued fraction.
What Is a Continued Fraction?
A continued fraction is a way to represent any real number as a nested sequence of integer additions and reciprocals. Every real number has a unique continued fraction expansion, and rational numbers always produce a finite continued fraction while irrational numbers produce an infinite one.
The standard form is written [a₀; a₁, a₂, a₃, …], which means:
a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + …)))
All partial quotients aₙ (except possibly a₀) are positive integers. The integer part a₀ may be zero or negative, but every subsequent term must be a positive integer.
How the Euclidean Algorithm Converts a Fraction
The continued fraction expansion of p/q is computed using the same idea as the greatest common divisor (GCD) algorithm:
- Set a₀ = ⌊p/q⌋ (floor division). The remainder is r = p − a₀·q.
- If r = 0, stop. The fraction is exact and the CF terminates.
- Otherwise set p = q, q = r and repeat to find a₁, a₂, …
Example — 355/113:
- 355 = 3·113 + 16 → a₀ = 3
- 113 = 7·16 + 1 → a₁ = 7
- 16 = 16·1 + 0 → a₂ = 16, done
Result: 355/113 = [3; 7, 16]
For decimals, the calculator first converts the decimal to an exact rational number using the decimal-places method (multiply by 10^d, GCD-reduce), then applies the same algorithm.
Understanding the Convergents Table
The n-th convergent pₙ/qₙ is the best rational approximation to the original number using a denominator no larger than qₙ. Convergents are computed with the recurrence:
p₋₂ = 0, p₋₁ = 1
q₋₂ = 1, q₋₁ = 0
pₙ = aₙ·pₙ₋₁ + pₙ₋₂
qₙ = aₙ·qₙ₋₁ + qₙ₋₂
Each convergent alternately overshoots and undershoots the true value. The error column shows |pₙ/qₙ − x|, illustrating exponential convergence — each step typically gains multiple decimal digits of precision.
Famous Constants and Their Continued Fractions
| Constant | CF Notation | Pattern |
|---|---|---|
| π (pi) | [3; 7, 15, 1, 292, 1, 1, …] | No pattern (transcendental) |
| φ (golden ratio) | [1; 1, 1, 1, 1, …] | All 1s — slowest convergence |
| e (Euler's number) | [2; 1, 2, 1, 1, 4, 1, 1, 6, …] | Partial pattern: 1,2k,1 repeats |
| √2 | [1; 2, 2, 2, 2, …] | Periodic — all 2s after a₀ |
| √3 | [1; 1, 2, 1, 2, 1, 2, …] | Periodic — 1,2 repeating |
| 355/113 | [3; 7, 16] | Finite — rational number |
| 22/7 (π approx) | [3; 7] | Finite — rational approximation |
Why 355/113 Is a Better Approximation of π Than 22/7
The continued fraction of π = [3; 7, 15, 1, 292, 1, 1, …] tells us something remarkable. After truncating at a₁ = 7 we get the convergent 22/7, which approximates π to 2.5 decimal places. Truncating at a₂ = 15 gives 333/106 (4 decimal places). Truncating at a₃ = 1 gives 355/113 — accurate to 6 decimal places despite a denominator of only 113.
The next coefficient a₄ = 292 is extraordinarily large. A large coefficient means the next convergent is a much better approximation — which is why 355/113 is so accurate and why there is no "nice" fraction that beats it until denominators reach the thousands.
This insight — that large partial quotients signal an especially good approximation just before them — is one of the key applications of continued fraction theory.
Applications of Continued Fractions
Best Rational Approximation
Find the simplest fraction within any desired error tolerance. Essential in gear-ratio design, music theory (equal temperament), and digital signal processing.
Calendar Systems
The Gregorian calendar's 97/400 leap-year rule is the third convergent of the tropical year's CF expansion — an optimal rational approximation of 365.2422 days.
Cryptography (RSA)
Wiener's attack on RSA uses continued fractions to recover the private key when the private exponent is small relative to the modulus.
Pell's Equation
The convergents of √N provide the fundamental solution to x² − Ny² = 1, connecting continued fractions to number theory and Diophantine equations.
Music & Acoustics
The 12-tone equal temperament scale corresponds to the convergent 12/1 from the CF of log₂(3/2), explaining why 12 semitones so closely approximate just intonation.
Numerical Analysis
Continued fraction representations of special functions (exp, tan, Bessel functions) often converge faster than Taylor series, especially far from the expansion point.
Frequently Asked Questions
What is the difference between a finite and infinite continued fraction?
Why does the golden ratio φ have the 'worst' continued fraction?
How does this calculator handle negative numbers?
What does 'max depth reached' mean?
Why did the convergents table stop early with an overflow warning?
How accurate is the decimal-to-rational conversion?
Related Calculators
Fraction Calculator
Add, subtract, multiply, and divide fractions
GCF & LCM Calculator
Greatest common factor and least common multiple
Set Theory Calculator
Union, intersection, difference, and Venn diagrams
Extended Euclidean Algorithm
GCD with Bézout coefficients step-by-step
Decimal to Fraction
Convert any decimal to its simplest fraction form
Modular Arithmetic Calculator
Modulo, modular inverse, and congruences