Every number can be turned into a ladder of whole numbers that leads to better and better fractions. The continued fraction calculator takes a number and the number of terms to use, and gives the coefficients a0 to a5, the numerator and denominator of the fraction built from those terms, the value of the fraction and the error compared with the number you entered.
How the calculation works
- Enter a positive number, such as 3.14159265358979 for pi or 1.41421356 for the square root of 2.
- Choose how many terms to use for the fraction, from 1 to 6. A term is one step of the expansion.
- The calculator takes the whole part a0, then takes the inverse of what is left, and repeats: a1 is the whole part of that inverse, and so on. A coefficient of 0 after the last term means that the expansion has ended.
- The fraction is built with the recurrence p(n) = a(n) × p(n−1) + p(n−2) and q(n) = a(n) × q(n−1) + q(n−2). It is the best fraction you can write with a denominator that size.
Example
Take π = 3.14159265358979. The whole part is 3, and the inverse of what remains is 7.0625, so a1 = 7. Then a2 = 15, a3 = 1, a4 = 292 and a5 = 1. With 4 terms the fraction is 355/113 = 3.14159292, off by only 2.7 × 10⁻⁷. With 5 terms, it is 103993/33102, and with 2 terms it is the old 22/7. The big coefficient 292 explains why 355/113 is so close.
Why it matters
Continued fractions give the best fraction for a given size of denominator. Gear makers use them to find tooth counts that give a ratio, calendar makers use them to match the length of a year, and musicians use them to find simple interval approximations. They are also a window into number theory.
Good to know
Inputs are decimals, so the expansion of a number such as 1/3 entered as 0.3333 will not end where the exact fraction would. Rounding in the input changes the later coefficients, so enter as many digits as you know. The fraction shown is reduced by the construction, so no further simplification is needed.
Related tools
The Fibonacci calculator is linked to the golden ratio, whose continued fraction is all ones, the golden ratio calculator gives the number itself, the geometric mean calculator helps with ratios, and the binomial expansion calculator covers another expansion of numbers.