Mathematics

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.

Decimal Input Fraction Input Convergents Table Error Bounds
Share this tool
Computing continued fraction…

Number or Fraction

Use / to enter a fraction. Negative numbers are supported.

Quick Load:

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:

  1. Set a₀ = ⌊p/q⌋ (floor division). The remainder is r = p − a₀·q.
  2. If r = 0, stop. The fraction is exact and the CF terminates.
  3. 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

ConstantCF NotationPattern
π (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?

A finite continued fraction has a last term and always represents a rational number (p/q). An infinite continued fraction represents an irrational number. This is analogous to the fact that rational numbers have terminating or repeating decimal expansions while irrationals do not.

Why does the golden ratio φ have the 'worst' continued fraction?

φ = [1; 1, 1, 1, …] has the slowest-converging continued fraction because all partial quotients are 1. Large partial quotients accelerate convergence; φ's all-1 expansion makes its convergents (Fibonacci ratios) converge as slowly as any irrational can — which is why φ is called the 'most irrational' number.

How does this calculator handle negative numbers?

Negative numbers use floor division: ⌊−7/3⌋ = −3, not −2. The first coefficient a₀ may be negative, but all subsequent coefficients aₙ (n ≥ 1) are positive integers. For example, −7/3 = [−3; 1, 2].

What does 'max depth reached' mean?

For decimal inputs, the calculator limits expansion to 30 terms; for fractions, 50 terms. If the continued fraction has not terminated by that depth, 'max depth reached' is shown. For irrational inputs this is expected — the expansion is truly infinite.

Why did the convergents table stop early with an overflow warning?

The numerators and denominators of convergents grow exponentially (Fibonacci-like). Once they would exceed the 64-bit integer limit (~9.2×10¹⁸), the calculator stops to avoid incorrect results. The coefficients themselves are still fully shown.

How accurate is the decimal-to-rational conversion?

Up to 15 significant decimal digits, conversion is exact (using integer arithmetic on the decimal string). Beyond 15 digits, floating-point representation limits apply — the calculator switches to a scale-by-10¹² fallback, which is accurate to about 12 decimal places.