ThisCalculator

Conversions

Continued Fraction Calculator: How to Use One

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Continued Fraction Calculator: How to Use One

This continued fraction calculator takes a decimal number or a simple fraction and converts it into a continued fraction of the form a₀ + 1/(a� + 1/(a₂ + 1/(a₃ + …))). You enter a single number, choose whether it is in decimal or fraction form, and the calculator returns the integer terms (a₀, a�, a₂, …) that exactly represent that number, along with the convergents (the fractions that approximate it). The result is shown as a list of integers, which you can use to understand the number’s best rational approximations or to explore continued fraction theory.

Formula

A continued fraction is an expression of the form:

a₀ + 1/(a� + 1/(a₂ + 1/(a₃ + …)))

where aâ‚€ is an integer (can be negative, zero, or positive) and all subsequent aáµ¢ are positive integers. For a given real number x, the terms are found by repeatedly:

  • Take the integer part of x as the next term aáµ¢.
  • Subtract that integer part to get the fractional part f.
  • If f is 0, stop.
  • Otherwise, set x = 1/f and repeat.

For a fraction p/q, the same process is equivalent to the Euclidean algorithm: divide p by q to get a quotient and remainder, then repeat with q and the remainder. The quotients are exactly the continued fraction terms.

Worked Example

Using the default value x = 3.14159 (a decimal approximation of π):

  1. Integer part: aâ‚€ = 3. Fractional part: 0.14159.
  2. Take reciprocal: 1/0.14159 ≈ 7.0625. Integer part: a� = 7. Fractional part: 0.0625.
  3. Reciprocal: 1/0.0625 = 16. Integer part: aâ‚‚ = 16. Fractional part: 0. Stop.

So the continued fraction is [3; 7, 16], which equals 3 + 1/(7 + 1/16) = 3 + 1/(7.0625) = 3 + 0.14159292… ≈ 3.14159292, matching the input to five decimal places. The calculator displays the terms as: 3, 7, 16. The convergents (the fractions you get by truncating the continued fraction) are:

  • 3/1 = 3
  • 3 + 1/7 = 22/7 ≈ 3.142857
  • 3 + 1/(7 + 1/16) = 355/113 ≈ 3.14159292

The last convergent, 355/113, is a well-known rational approximation of π.

When to Use a Continued Fraction Calculator

Continued fractions are useful in number theory, cryptography, and any field where you need the best rational approximations to a real number. For example, if you have a decimal like 0.333333, the calculator will quickly show that it is essentially 1/3. If you are working with ratios in engineering or physics, a continued fraction can reveal a simple fraction that is nearly exact, which is easier to work with than a long decimal. Astronomers use continued fractions to find the best integer ratios for gear trains or orbital periods.

You might also use this calculator to explore the continued fraction representation of irrational numbers like √2 or φ (the golden ratio). For √2, the continued fraction is [1; 2, 2, 2, …] — the terms repeat, showing that √2 is a quadratic irrational. For φ, the continued fraction is [1; 1, 1, 1, …], which is the simplest infinite continued fraction.

How to Read the Result

The output is a list of integers, usually written as [a₀; a�, a₂, a₃, …]. The semicolon after a₀ separates the integer part from the fractional part’s terms. For example, [2; 3, 4] means 2 + 1/(3 + 1/4). The convergents are the fractions obtained by cutting off the continued fraction at each term. The first convergent is a₀/1, the second is a₀ + 1/a�, and so on. These convergents are the best rational approximations to the original number, meaning no other fraction with a smaller denominator is closer.

If the input is a rational number (a fraction or a terminating decimal), the continued fraction will be finite — it will end after a finite number of terms. If the input is irrational, the continued fraction is infinite and never repeats (unless it is a quadratic irrational, which has a repeating pattern).

Common Mistakes and Limitations

  • Mixing up decimal and fraction input: If you enter a fraction like 22/7, make sure you select “Fractionâ€� mode, or enter the decimal value 3.142857. The calculator treats the input as a single number, not a division expression.
  • Rounding errors: If you enter a decimal that is rounded (e.g., 0.333 instead of 1/3), the continued fraction will be finite but may have a large final term, like [0; 3, 333]. That is correct for the rounded value, not for the intended fraction.
  • Negative numbers: For negative numbers, the integer part is the floor (e.g., for -2.3, the integer part is -3, not -2). The calculator handles this correctly, but be aware that the first term can be negative and all subsequent terms are positive.
  • Infinite continued fractions: The calculator can only display a finite number of terms. For irrational numbers, it will stop after a reasonable number of terms (e.g., 20), which is an approximation, not the exact infinite expansion.

How to Choose the Right Input

If you have a decimal that you suspect comes from a simple fraction, enter it with enough digits to avoid rounding errors. For example, if you have 0.6666666667, enter it as 0.6666666667 rather than 0.667, because the latter will give a different (and less useful) continued fraction. If you have a fraction, use the fraction mode to get the exact continued fraction without any decimal rounding. For irrational numbers like √2, you can enter a decimal approximation (e.g., 1.414213562) and the calculator will produce the first few terms, which should be [1; 2, 2, 2, …] until the rounding error shows up as a large final term.

Alternatives and Related Tools

If you need to convert a continued fraction back to a decimal or fraction, you can use a scientific calculator or a programming language like Python, but this calculator does that automatically in the convergents output. For finding the best rational approximation with a bounded denominator, you can use the convergents from this calculator. For other number theory operations, such as finding the greatest common divisor (GCD) or prime factorization, you would need a different calculator. This tool is specifically for continued fractions, so it does not handle other representations like Egyptian fractions or mixed radicals.

If you are working with the golden ratio or other quadratic irrationals, you might also be interested in a calculator that handles repeating continued fractions, but that is a more advanced topic. For most practical purposes, the finite approximation from this calculator is sufficient.

Frequently Asked Questions

What is a continued fraction used for?

Continued fractions give the best rational approximations to a real number, which is useful in engineering, physics, and computer science. For example, the approximation 355/113 for π comes from its continued fraction. They are also used in solving linear Diophantine equations and in the theory of irrational numbers.

Can a continued fraction be negative?

Yes. The first term a₀ can be any integer, including negative. For example, -1.5 has the continued fraction [-2; 2], because -2 + 1/2 = -1.5. The subsequent terms a�, a₂, … are always positive integers.

How do I convert a continued fraction back to a decimal?

You can work from the bottom up. For [a₀; a�, a₂, a₃], start with the last term a₃, then compute a₂ + 1/a₃, then a� + 1/(that result), and finally a₀ + 1/(that result). For example, [1; 2, 3] = 1 + 1/(2 + 1/3) = 1 + 1/(7/3) = 1 + 3/7 = 10/7 ≈ 1.428571.

Why does my decimal give a huge last term?

That usually means the decimal was rounded. For instance, 0.3333333333 gives [0; 3, 3333333333], because the tiny remainder after the first 3 is 0.0000000001, whose reciprocal is 10,000,000,000. If you had entered the exact fraction 1/3, you would get [0; 3] with no extra terms.

What is a convergent?

A convergent is the fraction you get by truncating the continued fraction at a certain point. For [a₀; a�, a₂, a₃], the convergents are a₀/1, (a₀a�+1)/a�, etc. These convergents are the best rational approximations to the original number, meaning no fraction with a smaller denominator is closer.

Is every rational number’s continued fraction finite?

Yes, every rational number has a finite continued fraction. For example, 22/7 has the continued fraction [3; 7], because 22/7 = 3 + 1/7. Irrational numbers have infinite continued fractions, but quadratic irrationals (like √2) have repeating patterns.

Related

Formula used
in x | Number | - | 3.14159 | 0
sel form | Input form | Decimal=1, Fraction=2
out cf | Continued fraction | - | cf_terms(x, form) | 0
out conv | Convergents | - | conv_terms(x, form) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.