Continued fraction calculator
Enter a fraction like 415/93, a decimal like 3.245, a square root like √23 or a continued fraction like [3; 7, 15, 1]. You get the expansion, the convergents hₖ/kₖ and, for square roots, the repeating period.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Type a fraction, a decimal, a square root or a bracketed continued fraction.
- For a square root choose how many terms to list. Read the expansion, the period and the convergents.
How it works
Rationals and decimals use exact integer arithmetic with floor division (so negative numbers work: −7/3 = [−3; 1, 2]). Square roots use the standard integer recurrence m’ = d·a − m, d’ = (n − m²)/d, a’ = ⌊(a₀ + m’)/d’⌋, which stops repeating when a = 2a₀. The convergents are exact fractions. A decimal such as 3.14159 is treated as exactly 314159/100000, not as a rounded approximation of π.
Worked example
415/93 = 4 remainder 43, 93/43 = 2 remainder 7, 43/7 = 6 remainder 1, 7/1 = 7. So 415/93 = [4; 2, 6, 7], with convergents 4, 9/2, 58/13 and 415/93.
√2 has convergents 1, 3/2, 7/5, 17/12, 41/29, which approach 1.41421356.
Tips
Frequently asked questions
What is a continued fraction?
A way to write a number as a0 + 1/(a1 + 1/(a2 + …)), shortened to [a0; a1, a2, …]. The first term is the whole part and the others are positive whole numbers. For example 415/93 = [4; 2, 6, 7].
How is a continued fraction found?
Take the whole part, then invert the fractional part and repeat. For a fraction this is the Euclidean algorithm, so it always ends. A decimal is first turned into the exact fraction it stands for (3.245 = 649/200), so its expansion also ends.
What are convergents?
Cutting the expansion after k terms gives the fraction hₖ/kₖ, computed by h = a·h₁ + h₂ and k = a·k₁ + k₂. Each is a best rational approximation for its size of denominator; for π = [3; 7, 15, 1, 292, …], 22/7 and 355/113 are convergents.
Why do square roots repeat?
By a theorem of Lagrange, the expansion of √n for a non-square whole number n is periodic. √2 = [1; 2, 2, 2, …], written [1; (2)], and √7 = [2; (1, 1, 1, 4)]. The period always ends with twice the first term.
Does a rational number have more than one continued fraction?
Every rational has two continued fractions, since [a; …, b] equals [a; …, b − 1, 1]. The tool shows the usual one whose last term is greater than 1.