Supported inputs include decimals, fractions like 22/7, constants pi and e, and square roots like sqrt(19).
Continued Fraction Explorer
Convert decimals, fractions, constants, and square roots into continued fractions.
Results are calculated automatically as you enter data.
Convergents
Each row reconstructs the number using one additional term.
Expansion steps and pattern notes
▼ See explanations and tips below ▼
Related Calculators
What Is a Continued Fraction?
A continued fraction is a way to write a number as an integer plus a nested chain of reciprocals. Instead of describing a number by decimal digits, it describes the number by a sequence of integer coefficients.
A simple continued fraction has the form:
The compact notation is:
Here, \(a_0=\lfloor x\rfloor\) is an integer and may be negative. In a simple continued fraction, the later coefficients \(a_1, a_2, a_3, \ldots\) are positive integers; they describe what happens after repeatedly taking the reciprocal of the remaining fractional part.
For example:
This is often written as:
The bar means the coefficient \(2\) repeats forever.
Continued fractions are useful because they connect real numbers, fractions, approximation, and the Euclidean algorithm. They are especially helpful when you want to approximate a decimal or irrational number with a fraction that is simpler to read and use.
Why Continued Fractions Matter
Decimals are familiar, but they are not always the best way to understand a number. A decimal expansion can be long without showing much structure. A continued fraction can reveal patterns that decimals hide.
Continued fractions are useful for:
- finding accurate rational approximations to real numbers;
- comparing how quickly different approximations improve;
- studying rational and irrational numbers;
- understanding how the Euclidean algorithm creates quotients;
- recognizing periodic patterns in square roots and other quadratic irrationals.
For example, the fraction \(\frac{355}{113}\) is a famous approximation to \(\pi\). Its continued-fraction form is short:
That short coefficient list explains why the fraction is so efficient: it captures a very good approximation with a relatively modest denominator.
Key Terms to Know
- Coefficient or partial quotient: An integer term \(a_0, a_1, a_2, \ldots\) in a continued fraction. In a simple continued fraction, \(a_0\) may be any integer and every later coefficient is positive.
- Simple continued fraction: A continued fraction whose numerators are all \(1\), such as \(a_0 + \frac{1}{a_1 + \frac{1}{a_2}}\).
- Convergent: A fraction made by stopping a continued fraction after a certain number of terms.
- Best convergent: In this calculator, the final convergent produced for the selected term count.
- Absolute error: The distance between an approximation and the target value.
- Periodic continued fraction: A continued fraction whose coefficients repeat in a cycle.
- Term count: The number of continued-fraction coefficients used in the displayed expansion.
- Euclidean algorithm: The repeated division process used to find greatest common divisors and to expand rational numbers as continued fractions.
- Floating-point precision: The finite precision used by ordinary browser numeric values. This matters for built-in constants and displayed decimal comparisons.
How Continued Fractions Work
The basic idea is simple: take the integer floor, then invert what is left.
Start with a real number \(x_0\). The first coefficient is:
If \(x_0 - a_0 = 0\), the process stops. Otherwise, invert the fractional remainder:
Then repeat:
Each time you keep the integer floor and continue with the reciprocal of the leftover fractional part.
Rational inputs and the Euclidean algorithm
For a fraction such as \(\frac{n}{d}\), continued-fraction coefficients come from repeated division. At each step, divide the current numerator by the current denominator:
Here:
- \(a\) is the next continued-fraction coefficient;
- \(r\) is the remainder;
- the next step uses \(d\) and \(r\).
When the remainder becomes \(0\), the continued fraction terminates. That is why rational numbers have finite continued-fraction expansions.
Convergents
A convergent is the fraction you get by stopping the continued fraction at a certain coefficient.
For:
the first few convergents are:
and so on.
The numerator and denominator of the \(n\)th convergent can be built with recurrence formulas:
with starting values:
The convergent itself is:
As more coefficients are included, the convergents usually become better approximations of the target number.
Square-root inputs
Nonsquare square roots have a special continued-fraction structure: their coefficient patterns repeat. For a positive integer \(N\) that is not a perfect square, the continued fraction of \(\sqrt{N}\) is periodic.
A common recurrence for square roots starts with:
Then it repeats:
For example:
and:
A perfect square is different. Since \(\sqrt{9}=3\), its continued fraction is simply:
Examples of Continued Fractions in Practice
Example 1: Expanding a rational number
Consider:
Use repeated division:
The quotients are \(3\), \(7\), and \(16\), so:
Because the remainder eventually becomes \(0\), this is a terminating continued fraction.
Example 2: Building convergents for \(\sqrt{2}\)
The continued fraction for \(\sqrt{2}\) is:
The first few convergents are:
| Terms used | Convergent | Decimal value |
|---|---|---|
| \([1]\) | \(\frac{1}{1}\) | \(1\) |
| \([1;2]\) | \(\frac{3}{2}\) | \(1.5\) |
| \([1;2,2]\) | \(\frac{7}{5}\) | \(1.4\) |
| \([1;2,2,2]\) | \(\frac{17}{12}\) | \(1.416666\ldots\) |
| \([1;2,2,2,2]\) | \(\frac{41}{29}\) | \(1.413793\ldots\) |
The true value is about \(1.41421356\), so the convergents move around the target while becoming more accurate.
Example 3: A negative fraction
Continued fractions can also describe negative values. With floor-based coefficients:
Since:
we get:
The first coefficient can be negative, while the later coefficients continue the reciprocal pattern.
How to Interpret the Result
The main continued-fraction result tells you which coefficient sequence represents the entered value up to the selected term count.
An ordinary selected-term result like:
means:
A separate Periodic square-root expansion card may show a result like:
This repeated-period notation means the coefficient block repeats indefinitely. The main result, coefficient list, and convergent table always show only the selected number of terms.
The best convergent shown by the calculator is the final convergent computed from the displayed coefficient list. It is best in the sense of the selected term count, not necessarily best under every possible rule such as a fixed maximum denominator.
The decimal value is the numeric value used for comparison. For exact fraction or decimal inputs, the coefficient expansion can terminate exactly, but the displayed decimal and error still depend on decimal formatting.
The absolute error is:
A smaller absolute error means the convergent is closer to the target value.
The digits of accuracy chart is based on the idea:
Larger bars mean smaller error. If the error is exactly zero for the displayed calculation, the chart treats that row as fully accurate for the current chart scale.
The pattern note should be read carefully:
- A terminating rational expansion is exact.
- A square-root period detected by the square-root recurrence is exact for supported square-root inputs.
- A possible repeating tail for other numeric inputs is a helpful clue, not a proof of exact periodicity.
Common Mistakes and Misconceptions
Mistake 1: Treating the term count as a denominator limit.
The term count controls how many continued-fraction coefficients are used. It does not directly say how large the denominator of the final convergent may be.
Mistake 2: Expecting every decimal pattern to prove a theorem.
A repeated-looking tail in a decimal or constant input may be caused by numeric approximation. Exact periodicity is guaranteed for supported nonsquare square-root inputs, not for every displayed pattern.
Mistake 3: Entering unsupported square-root notation.
Use sqrt(2), not √2, sqrt 2, or sqrt(2)+1.
Mistake 4: Expecting arbitrary expressions to parse.
Inputs such as 2*pi, sin(1), 1+sqrt(2), and mixed numbers are not supported.
Mistake 5: Using a comma as a decimal separator.
Use a period for decimals, such as 3.14, not 3,14.
Mistake 6: Entering a fraction with denominator zero.
A fraction such as 5/0 is undefined and cannot produce a continued fraction.
Mistake 7: Assuming pi and e are symbolic.
The constants pi, π, and e are treated as stored numeric values. Their displayed expansions are useful approximations, not symbolic infinite expansions.
When to Use Continued Fractions
Use continued fractions when you want to:
- turn a real number into a structured sequence of integer coefficients;
- find fraction approximations for a decimal or constant;
- compare how successive convergents improve;
- study why rational inputs terminate;
- explore periodic continued fractions for square roots;
- teach or learn the Euclidean algorithm in a visual way;
- analyze approximation error term by term.
Continued fractions are especially useful in number theory and approximation problems, but they are also helpful for anyone who wants a clearer fraction-based view of a number.
Limitations and Things to Keep in Mind
This calculator works with real, dimensionless mathematical values. It does not handle units, complex numbers, or general symbolic algebra.
Supported input formats include:
- decimal numbers;
-
integer fractions such as
355/113; -
piorπ; -
e; -
sqrt(n)where \(n\) is a positive safe integer.
Unsupported inputs include:
-
sqrt(2)+1; -
2*pi; -
sin(1); - mixed numbers;
-
comma decimals such as
3,14; -
Unicode square-root notation such as
√2; -
decimal or fractional radicands inside
sqrt(); - nonpositive square-root radicands;
- complex values.
Finite decimal and scientific-notation inputs are parsed as exact decimal rationals before their coefficients are generated. If an exact coefficient would exceed the calculator's safe bound, the calculator rejects the input rather than rounding a nonzero value to zero. The built-in constants pi and e still use finite browser numeric values, so their displayed expansions are approximations.
For fraction and decimal inputs, the coefficient expansion is generated using exact integer division, but displayed decimal comparisons still require a finite numeric value. Very large values may be rejected if they cannot be compared safely or if a coefficient exceeds the safe bound.
For square-root inputs, perfect squares return a one-term exact expansion. Nonsquare positive integer radicands produce periodic notation when the period is found within the calculator's safety limit.
Displayed decimal values and errors are rounded for readability. Main decimal and error outputs are generally shown with up to 12 decimal places, while very large or very small values may use exponential notation.
How to Use This Calculator
-
Enter a supported value: a decimal number, a fraction such as
355/113,pi,π,e, orsqrt(n). - Choose the number of continued-fraction terms to compute.
-
Use an example shortcut, if available, to load common examples such as
pi,e,sqrt(2), or355/113. - Read the continued-fraction notation to see the coefficient sequence.
- Check the best convergent, best decimal, and absolute error to understand the approximation.
- Review the convergent table to compare each term, coefficient, fraction, decimal approximation, and error.
- Use the accuracy chart to see which convergents improve the result most.
- Hover over chart rows, when supported, to inspect convergent details.
- Download the chart as a PNG if the download button is visible and supported by your browser.
Frequently Asked Questions
What does [a0; a1, a2, ...] mean?
It means:
The semicolon separates the integer part from the reciprocal part of the continued fraction.
Why do rational numbers terminate?
A rational number can be expanded by repeated integer division. Since the Euclidean algorithm eventually reaches a zero remainder, the continued fraction stops after finitely many coefficients.
Why do square roots often show repeating patterns?
Nonsquare square roots of positive integers are quadratic irrationals. Their simple continued fractions eventually repeat, and for square roots the repeating block can be found with a standard recurrence.
Is the final convergent always the best possible fraction?
It is the final convergent for the selected term count. Continued-fraction convergents are usually very strong rational approximations, but “best” can mean different things depending on whether you limit the number of terms, the denominator size, or another condition.
Why does adding more terms sometimes create very large fractions?
Each new coefficient updates the numerator and denominator using recurrence formulas. As more terms are added, denominators can grow quickly, especially when the continued fraction contains larger coefficients.
Why are pi and e not exact?
They are irrational constants with infinite expansions. In the calculator, they are represented by finite stored numeric values, so the displayed continued fraction is based on that finite approximation.
What does absolute error tell me?
Absolute error tells you how far the convergent's decimal value is from the target value. An error of \(0.001\) means the approximation is one-thousandth away from the value used for comparison.
Sources and References
- A. Ya. Khinchin, Continued Fractions, English translation, 1964; Dover reprint. Available through the Internet Archive and reviewed by the Mathematical Association of America: Internet Archive item and MAA Review.
- C. D. Olds, Continued Fractions, Anneli Lax New Mathematical Library, Vol. 9, Mathematical Association of America, 1963. Book details from the American Mathematical Society: AMS Bookstore.
- G. H. Hardy, E. M. Wright, D. R. Heath-Brown, and Joseph H. Silverman, An Introduction to the Theory of Numbers, 6th ed., Oxford University Press, 2008. Continued fractions and rational approximation chapters listed in the Google Books preview: Google Books.
- Robert M. Corless, “Summary of Classical Results,” Continued Fractions and Chaos, Centre for Experimental and Constructive Mathematics, Simon Fraser University: CECM/SFU.
- Eric W. Weisstein, “Continued Fraction,” CRC Concise Encyclopedia of Mathematics archive: MSU CRC Math Archive.
- Bruce Ikenaga, “Finite Continued Fractions,” Millersville University: Finite Continued Fractions.
- Bruce Ikenaga, “Periodic Continued Fractions,” Millersville University: Periodic Continued Fractions.
- Eric W. Weisstein, “Pell Equation,” Wolfram MathWorld, for square-root continued fractions and convergent recurrences: MathWorld.
- TC39, ECMAScript Language Specification, numeric-value sections for Number and BigInt behavior: ECMAScript Data Types and Values and Mathematical Operations.