Continued Fraction Calculator
Evaluate a finite continued fraction from the bottom up and read off its exact fraction and decimal value.
What it does
A finite simple continued fraction is an integer a0 plus a chain of unit fractions: a0 + 1/(a1 + 1/(a2 + ... + 1/an)). The NIST Digital Library of Mathematical Functions gives the general notation and calls the truncated versions convergents, while Trinity College Dublin's number theory notes treat the simple case where the numerators are all 1 and the later coefficients are positive integers. The compact bracket form [a0; a1, ..., an] saves a great deal of writing.
The expression is nested, so the natural way to evaluate it starts at the bottom. Take the last coefficient an as the first tail value, move up one step by computing a(n-1) + 1/tail, and keep going until you reach a0. Each step treats the part underneath as a single number, which is exactly what the nested fraction asks for.
There is a second route through the convergents. Set p at minus 2 to 0, p at minus 1 to 1, q at minus 2 to 1 and q at minus 1 to 0, then use p sub k = a sub k times p sub (k-1) plus p sub (k-2), with the same rule for q. The final p over q is the value of the whole string. The MIT number theory lecture notes and the Trinity College chapter both state this recurrence, and it makes the rational nature of every finite string obvious.
This page takes up to five coefficients. Fill as many boxes as you need in order and leave the rest empty. It prints the decimal value to eight places, the fraction reduced to lowest terms, and the bracket notation. A gap between filled boxes is rejected, as is any string whose running tail reaches zero before a division.
One pleasant example lives at the edge of the topic. Setting every coefficient to 1 gives ratios of consecutive Fibonacci numbers, and those ratios creep toward the golden ratio as the string grows. Five ones give 8/5, which the MacTutor history of mathematics pages list among the convergents. A finite string only approximates such an irrational limit, and this tool reports exactly that finite value.
How to use
- Enter the whole number a0 in the first box. It may be zero or negative.
- Enter a1 in the next box. In the simple form this and all later coefficients are positive whole numbers.
- Add a2, a3 and a4 if you want a longer fraction, leaving any unused boxes empty.
- Fill the boxes in order, since a blank box followed by a number is treated as an error.
- Read the decimal value, the exact fraction and the bracket notation in the result panel.
- Set all five boxes to 1 to watch the Fibonacci ratios build toward the golden ratio.
Formula
- a0
- The first coefficient, any whole number. It sets the integer part of the value.
- a sub k
- A later coefficient, normally a positive whole number in the simple form.
- n
- The index of the last coefficient supplied, at most 4 here so up to five coefficients.
- t
- The running tail value during the bottom-up pass.
- p sub k, q sub k
- Numerator and denominator of the kth convergent, built by the recurrence.
- C
- The value of the whole continued fraction.
The bottom-up pass and the convergent recurrence give the same number, and the recurrence explains why every finite simple continued fraction is rational. A tail of zero before a division would make the expression undefined, so the tool rejects those coefficient strings. The fraction row is reduced by the greatest common divisor of the final numerator and denominator, while the decimal row is rounded to eight places.
Worked example
Example: the coefficients 2, 3, 1, 4
Defaults: a0 = 2, a1 = 3, a2 = 1, a3 = 4 and an empty fifth box. That is the fraction [2; 3, 1, 4] with four coefficients.
- The coefficients in order are 2, 3, 1 and 4. The empty fifth box means the tool uses four coefficients.
- Start at the bottom with the last coefficient, so the first tail value is 4.
- Move up to a2 = 1: 1 + 1/4 = 5/4, which is 1.25.
- Move up to a1 = 3: 3 + 1/(5/4) = 3 + 4/5 = 19/5, which is 3.8.
- Move up to a0 = 2: 2 + 1/(19/5) = 2 + 5/19 = 43/19.
- As a decimal, 43/19 = 2.2631578947..., so the tool prints 2.26315789.
- A convergent check agrees: [2] = 2, [2; 3] = 7/3, [2; 3, 1] = 9/4 and [2; 3, 1, 4] = 43/19.
Reference table
| Coefficients | Bottom-up tail values | Fraction and decimal |
|---|---|---|
| [2; 3, 1, 4] | 4, 5/4, 19/5, 43/19 | 43/19 = 2.26315789 |
| [1; 2, 3] | 3, 7/3, 10/7 | 10/7 = 1.42857143 |
| [1; 1, 1, 1, 1] | 1, 2, 3/2, 5/3, 8/5 | 8/5 = 1.60000000 |
| [0; 1, 2, 3] | 3, 7/3, 10/7, 7/10 | 7/10 = 0.70000000 |
Limits
- At most five coefficients are accepted, so long expansions of irrational numbers are cut short here.
- Every numerator in this form is 1. General continued fractions with other numerators need a different calculation.
- Coefficients must be whole numbers within one million, and the boxes must be filled without gaps.
- The decimal row is rounded to eight places; the fraction row holds the exact value of the finite string.
Common mistakes
- Putting a decimal or fraction in a0 when the simple form asks for whole numbers.
- Leaving a blank box between two filled ones, which changes which coefficient sits above which.
- Reading the rounded decimal as the exact answer while the fraction row carries the full value.
- Expecting a finite string to equal an irrational constant. Truncating the golden ratio gives 8/5, not 1.61803399.
- Starting the evaluation at the top instead of the bottom, which produces a different number.
Try it yourself
Quick checks. Answers sit tucked under each question.
Evaluate [1; 2, 3] and name the exact fraction.
Work from the bottom: 3, then 2 + 1/3 = 7/3, then 1 + 1/(7/3) = 10/7. The tool shows 1.42857143, the fraction 10/7 and the notation [1; 2, 3].
What do five coefficients of 1 give, and what do they approach?
[1; 1, 1, 1, 1] works out to 8/5, shown as 1.60000000. These are ratios of consecutive Fibonacci numbers, and longer strings of ones move toward the golden ratio 1.61803399.
Find the value of [0; 1, 2, 3].
From the bottom: 3, then 2 + 1/3 = 7/3, then 1 + 3/7 = 10/7, then 0 + 7/10 = 7/10. The decimal row reads 0.70000000 and the fraction row reads 7/10.
Questions
What is a continued fraction?
A way to write a number as an integer plus the reciprocal of another number, which is written the same way. Stopping after finitely many steps always gives a rational number.
Why evaluate from the bottom?
The expression is nested, so the innermost denominator must be known before the layer around it can be found. Starting at the last coefficient avoids guessing at any step.
What does the notation [a0; a1, a2] mean?
It is shorthand for a0 + 1/(a1 + 1/a2). The semicolon separates the integer part from the coefficients that follow.
Can a0 be zero or negative?
Yes. Zero gives a value between 0 and 1 when the later coefficients are positive, and a negative a0 shifts the whole fraction down by an integer.
What if one of the coefficients is zero?
A zero later coefficient can still work. The tool only rejects a string whose running tail reaches zero before a division, because that step is undefined.
How does this connect to the golden ratio?
Taking every coefficient as 1 gives ratios of consecutive Fibonacci numbers. Five ones give 8/5, and longer strings creep toward 1.61803399.
Sources
- NIST Digital Library of Mathematical Functions, 1.12 Continued Fractions
- Trinity College Dublin, Number Theory Chapter 17: Continued fractions
- MacTutor History of Mathematics, Continued fractions and the Fibonacci sequence