Continued Fraction Converter

Express any real number as a continued fraction expansion

Compute the continued fraction expansion of any real number and list its convergents, the successively better rational approximations. Shows standard bracket notation and each convergent's error. Runs entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is a continued fraction?

A continued fraction expresses a number as an integer plus the reciprocal of another integer plus the reciprocal of another, and so on. It is written compactly as [a0; a1, a2, ...] and gives the most natural sequence of rational approximations to a real number.

A continued fraction writes a number as an integer plus a reciprocal of an integer plus a reciprocal, nesting indefinitely. It produces the cleanest possible ladder of rational approximations — the convergents — which is why it underlies calendar design, gear ratios, and the best rational approximations of mathematical constants.

What continued fractions are and why they matter

A simple continued fraction represents any real number as:

x = a0 + 1 / (a1 + 1 / (a2 + 1 / (a3 + ...)))

Written compactly as [a0; a1, a2, a3, ...], where each ak is a non-negative integer. This representation has a remarkable property: truncating after any term gives you the best possible rational approximation of the original number for any fraction with a denominator that size or smaller. No other fraction with that denominator gets closer to the true value.

This is why continued fractions appear across applied mathematics:

  • Pi: [3; 7, 15, 1, 292, …] — truncating after 7 gives 22/7, after 15 gives 355/113, both famous pi approximations
  • Calendar design: The Gregorian calendar’s 97-leap-years-in-400 structure comes from the continued fraction expansion of the solar year’s fractional day
  • Gear ratios: Mechanical engineers use convergents to find gear tooth counts that approximate a desired ratio with small integers
  • Music theory: Tuning systems use continued fractions to approximate just intervals with small-integer frequency ratios

How the algorithm works step by step

The expansion algorithm is a simple iteration:

pi = 3.14159265...
  Step 1: a0 = floor(3.14159) = 3,  remainder = 0.14159...
  Step 2: reciprocal = 1/0.14159 = 7.0625...,  a1 = 7, remainder = 0.0625...
  Step 3: reciprocal = 1/0.0625 = 15.99...,     a2 = 15, remainder = 0.99...
  Step 4: reciprocal = 1/0.99 = 1.0006...,      a3 = 1
  pi ≈ [3; 7, 15, 1, 292, ...]

Each convergent is computed from the sequence using the recurrence:

p_k = a_k × p_(k-1) + p_(k-2)
q_k = a_k × q_(k-1) + q_(k-2)

with starting values p_{-1} = 1, p_0 = a_0, q_{-1} = 0, q_0 = 1. The convergent at step k is p_k / q_k. Convergents alternate above and below the true value and get successively closer — the error at step k is bounded by 1/(q_k × q_{k+1}).

Why a large term means a very good approximation

When a term in the continued fraction is large — like the 292 in pi’s expansion or the 15 two steps earlier — the next convergent is dramatically more accurate than the previous one. Intuitively, a large term means the “current” convergent was already very close, and the correction from the next term is correspondingly tiny. This is why 22/7 (stopping at a1 = 7) is a good approximation of pi: the next term is 15, a large number, signalling that 22/7 was already nearly exact and 355/113 is even better.

Worked examples of important constants

NumberExpansionNotable convergents
pi[3; 7, 15, 1, 292, …]22/7, 333/106, 355/113
sqrt(2)[1; 2, 2, 2, 2, …]1/1, 3/2, 7/5, 17/12, 41/29
phi (golden ratio)[1; 1, 1, 1, 1, …]1/1, 2/1, 3/2, 5/3, 8/5, 13/8
e (Euler’s number)[2; 1, 2, 1, 1, 4, 1, 1, 6, …]3/1, 8/3, 11/4, 19/7

The golden ratio has all 1s because it converges as slowly as possible — it is the “most irrational” number, which is why Fibonacci numbers (its convergent numerators and denominators) appear in plant growth patterns.

Tips and notes

The output uses standard bracket notation with a semicolon after the integer part, for example [3; 7, 15, 1]. Each convergent is listed with its decimal value and absolute error. Because the input is read as a floating-point decimal, very long expansions eventually reflect floating-point rounding rather than the true mathematical value; keep the term count modest for typical inputs, and for high-precision work provide a high-precision decimal string.