Continued Fraction Expansion

Expand any number into its continued fraction [a₀; a₁, a₂, …].

Open tool

Overview

The Continued Fraction Expansion tool turns any real number into its continued fraction representation [a0; a1, a2, ...] and lists the best rational approximations along the way. It uncovers structure that decimals hide — for example 355/113 jumps right out of π's expansion as a famously good rational approximation.

Number-theory students learning Stern-Brocot trees, hobbyists exploring irrationals and engineers picking a rational approximation for gear ratios or clock dividers will all find it useful. Each convergent gives the best rational approximation for its denominator size.

How it works

Given a real number x, set a0 = floor(x) and x1 = 1 / (x - a0). Repeat: a_k = floor(x_k) and x_{k+1} = 1 / (x_k - a_k) until the remainder becomes zero (rational input) or you hit a precision floor.

The convergents p_k / q_k are built recursively: p_k = a_k * p_{k-1} + p_{k-2} and q_k = a_k * q_{k-1} + q_{k-2} with seeds (p_-1, q_-1) = (1, 0) and (p_0, q_0) = (a_0, 1). These convergents alternate above and below x and are the best rational approximations.

Examples

22/7  →  [3; 7]  (terminates, since 22/7 is rational)
π  →  [3; 7, 15, 1, 292, 1, ...]
   →  convergents: 3/1, 22/7, 333/106, 355/113, ...
golden ratio φ  →  [1; 1, 1, 1, 1, ...]
   →  convergents: 1, 2, 3/2, 5/3, 8/5, 13/8, ...
e  →  [2; 1, 2, 1, 1, 4, 1, 1, 6, ...]

FAQ

Why are some expansions finite and others infinite?

Rational numbers terminate. Irrational numbers go on forever. Quadratic irrationals (like sqrt(2)) eventually become periodic.

Is 355/113 really that good?

Yes — it agrees with π to seven digits. The large 292 in π's expansion is what makes the previous convergent so accurate.

What's special about the golden ratio's expansion?

It's [1; 1, 1, ...] — the slowest possible convergence. That makes φ the "most irrational" number, useful in quasicrystals and irrational rotation.

How many terms should I request?

A dozen or so is plenty for most uses. The convergents grow exponentially, so even short expansions yield denominators in the millions.

Are the convergents always in lowest terms?

Yes — gcd(p_k, q_k) = 1 for every convergent. That's a property of the recurrence.

Try Continued Fraction Expansion

An unhandled error has occurred. Reload ×