Continued Fraction Calculator
A continued fraction expresses a number as a0 + 1/(a1 + 1/(a2 + ...)) where each coefficient is a positive integer called a partial quotient. Every rational number has a finite continued fraction, while irrational numbers have infinite ones with periodic or non-periodic coefficients. This calculator converts any decimal input to its continued fraction representation, computes the sequence of convergents (successive rational approximations p/q), and shows the error of each convergent. The conversion algorithm is: take the floor of x to get a0, subtract it, take the reciprocal of the remainder, and repeat. Convergents are the best rational approximations to a given number in a precise sense: no fraction with a smaller denominator comes closer. For example, 22/7 and 355/113 are both convergents of pi, making them exceptionally good approximations. Continued fractions appear in Diophantine approximation theory, the Euclidean algorithm, Pell equations, and cryptography.
Convergents table
| n | a_n | Convergent p/q | Decimal value | Error |
|---|
Continued fraction algorithm
a0 = floor(x); r0 = x - a0
a1 = floor(1/r0); r1 = 1/r0 - a1
a2 = floor(1/r1); r2 = 1/r1 - a2
...
Convergents: p_n = a_n*p_(n-1) + p_(n-2)
q_n = a_n*q_(n-1) + q_(n-2)
with p_(-1)=1, p_0=a0, q_(-1)=0, q_0=1
Continued fractions: frequently asked questions
What is a continued fraction?
A continued fraction is an expression of the form a0 + 1/(a1 + 1/(a2 + 1/(a3 + ...))) where a0 is an integer and a1, a2, a3, ... are positive integers called partial quotients. Every real number has a continued fraction expansion; rational numbers have finite expansions, and irrational numbers have infinite ones.
What are convergents of a continued fraction?
Convergents are the successive rational approximations obtained by truncating a continued fraction. The nth convergent p_n/q_n satisfies |x - p_n/q_n| less than 1/q_n^2. By a theorem of Legendre, any fraction satisfying this bound must be a convergent, making convergents the best rational approximations to x with denominator up to q_n.
What is the continued fraction of pi?
Pi = [3; 7, 15, 1, 292, 1, 1, 1, 2, ...]. The first convergent is 3/1. The second is 22/7, a familiar approximation to pi. The third is 333/106, and the fourth is 355/113, which is accurate to 7 decimal places. The large partial quotient 292 means 355/113 is an exceptionally good approximation.
What is the continued fraction of the golden ratio?
The golden ratio phi = (1+sqrt(5))/2 = [1; 1, 1, 1, 1, ...], the simplest possible infinite continued fraction with all partial quotients equal to 1. This makes the golden ratio the hardest real number to approximate by rationals, which is why it appears in phyllotaxis and the study of quasi-crystals.
How do you convert back from a continued fraction to a decimal?
To evaluate [a0; a1, a2, ..., an], start from the last partial quotient and work backwards: start with an, compute 1/(an) and add a(n-1), compute 1/(result) and add a(n-2), and so on until you reach a0. This is exactly the reverse of the conversion algorithm.
Sources
- Continued fractions and Diophantine approximation: Wolfram MathWorld, Continued Fraction.
- NIST Digital Library of Mathematical Functions: DLMF 1.12, Continued Fractions.
Reviewed by the CalculatorHub team, edited by James Graham, 14 June 2026. See our methodology.