Continued Fraction Calculator - Convergents & Expansion

Every term, every convergent, and the best fraction under your limit.

Expand a decimal, fraction, square root, π or e into [a0; a1, a2, …] with exact integer arithmetic, or type a list of terms and get the fraction it stands for.

Decimals are taken as exact. Roots: √2, sqrt(2), 2√3, √2/2, (1+√5)/2. Words: pi, e, phi.

Finds the closest fraction with a denominator up to this value. Leave blank to skip.

Numbers up to 300 digits per part; radicands up to 10¹⁵; denominator limits up to 1,000,000,000,000,000,000 (10¹⁸). π and e are computed to 400 digits. Term lists up to 200 terms.

Continued fraction of π

[3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, 1, 84, 2, 1, 1, 15, 3, 13, 1, 4, …]

π is irrational and not the root of any quadratic, so its expansion never ends and never repeats. The 403 terms listed are exactly those pinned down by 400 computed digits; nothing beyond them is claimed.

Written out

3 +17 +115 +11 +1

Decimal value

3.1415926535897932384626433…

Terms

403

certain terms, no end

Last convergent shown

5,419,351/1,725,033

n = 11

Best with q ≤ 100

311/99

semiconvergent

Closest fraction with denominator ≤ 100

311/99 = 3.141414141414141…

Off by 1.79 × 104. This is a semiconvergent: (22 × 14 + 3)/(7 × 14 + 1), squeezed between the convergents 22/7 and 333/106. The convergent 22/7 alone is off by 0.00126, so the in-between fraction wins under this limit.

Convergents pₙ/qₙ, each the closest fraction to π among all fractions with denominator up to qₙ

naₙpₙ/qₙDecimalError |x − pₙ/qₙ|qₙ² × error
03330.1420.1416
1722/73.142857142857…0.001260.0620
215333/1063.141509433962…8.32 × 1050.9351
31355/1133.141592920353…2.67 × 1070.0034
4292103,993/33,1023.141592653011…5.78 × 10100.6332
51104,348/33,2153.141592653921…3.32 × 10100.3659
61208,341/66,3173.141592653467…1.22 × 10100.5381
71312,689/99,5323.141592653618…2.91 × 10110.2887
82833,719/265,3813.141592653581…8.72 × 10120.6138
911,146,408/364,9133.141592653591…1.61 × 10120.2145
1034,272,943/1,360,1203.141592653589…4.04 × 10130.7475
1115,419,351/1,725,0333.141592653589…2.21 × 10140.0659

The last column is always below 1, because every convergent satisfies |x − pₙ/qₙ| < 1/(qₙ qₙ₊₁). A small value means a fraction punching far above its denominator; it happens exactly when the next term aₙ₊₁ is large.

Correct decimal digits of each convergent

0.802.914.126.639.249.559.9610.5711.1811.8912.41013.71115.21215.813n (index of the convergent)

Digits = −log₁₀ of the error. A tall jump marks a convergent that is followed by a large term.

How the terms were computed

xₖ₊₁ = 1/(xₖ − aₖ), carried out on a 400-digit value. Because π is only known to that precision, the calculator expands the whole interval [x − 2·10⁻⁴⁰⁰, x + 2·10⁻⁴⁰⁰] and keeps a term only when every number in the interval shares it.

kxₖ (first 12 decimals)aₖ = ⌊xₖ⌋
03.1415926535893
17.0625133059317
215.99659440668515
31.0034172310131
4292.634591014395292
51.5758180896281
61.7366595770641
71.3574791275841

How to Use This Calculator

  1. Leave What do you want? on Expand a number and type the number: a decimal such as 3.14159, a fraction such as 415/93, a mixed number, a root such as √2 or (1+√5)/2, or the words pi, e or phi. The presets load common examples.
  2. Read the bracket line for the terms. A block in parentheses repeats forever; an ellipsis means the expansion goes on past the certain terms shown. Use Copy terms to copy the whole list.
  3. Fill in Largest denominator allowed to get the closest fraction under that limit, with the runner-up it beat. Clear the field to skip this.
  4. Scan the convergent table: the error column tells you how far each fraction is from the number, and the last column shows which convergents are unusually good.
  5. Switch to Evaluate a list of terms to go the other way: type [3; 7, 15, 1] for a fraction, or [1; (2)] with a block in parentheses for a repeating expansion, and read the exact value.
average • 0 ratings
Your rating
Tap a star to rate

Your rating helps improve Continued Fraction Calculator - Convergents & Expansion. We store only an anonymized vote (no personal data).

Share this calculator

Help others solve their calculations

Found this calculator helpful? Share it with your friends, students, or colleagues who might need it!

Continued Fraction Calculator: Building the Best Rational Approximation of Any Number

About the Author

Marko Šinko - Co-Founder & Lead Developer

Marko Šinko

Co-Founder & Lead Developer, AI Math Calculator

Lepoglava, Croatia
Advanced Algorithm Expert

Croatian developer with a Computer Science degree from University of Zagreb and expertise in advanced algorithms. Co-founder of award-winning projects, ensuring precise mathematical computations and reliable calculator tools.

📅 Published:
Continued fraction calculator illustration: nested fraction bars stepping down a staircase, with brackets closing in on a target line

A continued fraction calculator rewrites a number as a whole part plus one over (a whole part plus one over …). For π the calculator returns [3; 7, 15, 1, 292, 1, 1, 1, 2, …], and stopping early gives the fractions 3, 22/7, 333/106 and 355/113. Those are the convergents, and each one is the closest fraction to π among all fractions whose denominator is no larger than its own. That single property is why continued fractions exist: they hand you the best possible fraction for any budget on the denominator.

The notation [a0; a1, a2, …] means a0 + 1/(a1 + 1/(a2 + …)), where a0 is any integer and every later term is a positive integer. The tool above accepts a decimal, a fraction, a mixed number, a square-root expression such as √2 or (1 + √5)/2, or the words pi and e; it lists the terms, the convergents with their exact errors, and the closest fraction under any denominator limit you set. Type a list of terms instead and it folds them back into an exact fraction or, for a repeating list, an exact surd. Everything below is computed with exact integers, and π and e are carried to 400 digits so that every listed term is certain.

How to Expand a Number by Hand: Floor, Subtract, Flip

Take 415/93. The whole part is 4, because 4 × 93 = 372 and 5 × 93 would be too big. What is left is 43/93, and the trick is to flip it: 43/93 = 1/(93/43). Now repeat on 93/43, whose whole part is 2 with 7/43 left over. Flip again: 43/7 = 6 remainder 1. Flip once more: 7/1 = 7 exactly, and the process stops.

StepDivisionTermFlip what is left
1415 = 4 × 93 + 43493/43
293 = 2 × 43 + 7243/7
343 = 6 × 7 + 167/1
47 = 7 × 1 + 07done

So 415/93 = [4; 2, 6, 7] = 4 + 1/(2 + 1/(6 + 1/7)). Look at the left column of divisions: 415 = 4 × 93 + 43, 93 = 2 × 43 + 7, 43 = 6 × 7 + 1. That is the Euclidean algorithm for gcd(415, 93), and the terms of the continued fraction are exactly its quotients. The extended Euclidean algorithm calculator shows the same quotient column for any pair of integers, which is why a fraction’s expansion is always finite: the remainders 43, 7, 1, 0 must reach zero.

A decimal is just a fraction with a power-of-ten denominator, so 3.14159 = 314159/100000 expands the same way, to [3; 7, 15, 1, 25, 1, 7, 4]. An irrational number never reaches a zero remainder, so its expansion never ends. Either way, the calculator does the floor-subtract-flip loop on exact integers; if you only want the reduced fraction of a decimal, the decimal to fraction calculator stops at that first step.

Convergents: The Fractions Worth Keeping

Cut the expansion after n + 1 terms and evaluate what is left; the result pₙ/qₙ is the n-th convergent. You never have to unwind nested fractions to get it, because two recurrences build the numerators and denominators forward from the terms:

pₙ = aₙ × pₙ₋₁ + pₙ₋₂ (start with p₋₁ = 1, p₋₂ = 0)

qₙ = aₙ × qₙ₋₁ + qₙ₋₂ (start with q₋₁ = 0, q₋₂ = 1)

For π the terms 3, 7, 15, 1, 292 give p: 3, 22, 333, 355, 103993 and q: 1, 7, 106, 113, 33102. Check one line: 355 = 1 × 333 + 22 and 113 = 1 × 106 + 7. Here is what the calculator reports for the first six convergents of π:

naₙpₙ/qₙErrorqₙ² × errorCorrect digits
033/11.42 × 10⁻¹0.1420.8
1722/71.26 × 10⁻³0.0622.9
215333/1068.32 × 10⁻⁵0.9354.1
31355/1132.67 × 10⁻⁷0.00346.6
4292103993/331025.78 × 10⁻¹⁰0.6339.2
51104348/332153.32 × 10⁻¹⁰0.3669.5

Two facts about consecutive convergents fall out of the recurrence. First, pₙqₙ₋₁ − pₙ₋₁qₙ = (−1)ⁿ⁻¹: for π, 22 × 1 − 3 × 7 = 1, then 333 × 7 − 22 × 106 = −1, then 355 × 106 − 333 × 113 = 1. A determinant of ±1 means each convergent is automatically in lowest terms, so there is never a call to the simplify fractions calculator afterwards. Second, the convergents alternate sides: 3 and 333/106 are below π, 22/7 and 355/113 are above, and the number is always trapped between neighbours.

Why 355/113 Is So Good: Look at the Next Term

The error of a convergent is pinned between two bounds that involve the next denominator:

1/(qₙ(qₙ + qₙ₊₁)) < |x − pₙ/qₙ| < 1/(qₙ qₙ₊₁)

Since qₙ₊₁ = aₙ₊₁qₙ + qₙ₋₁, a large next term makes qₙ₊₁ huge and the error tiny. The term after 355/113 is 292, so q₄ = 292 × 113 + 106 = 33,102 and the error must be below 1/(113 × 33,102) = 2.67 × 10⁻⁷. The actual error, 2.668 × 10⁻⁷, sits right under that ceiling: a three-digit denominator buys six and a half correct decimals. Compare 333/106, which is followed by a 1. Its error is 8.3 × 10⁻⁵, only a little better than the bound would allow, and the qₙ² × error column shows the difference starkly: 0.935 for 333/106 against 0.0034 for 355/113. That column is always below 1, because the upper bound is smaller than 1/qₙ², and the closer it gets to 1 the more ordinary the convergent is.

The deeper statement, proved by Lagrange, is that convergents are exactly the fractions that beat every fraction with a smaller denominator when you measure the error as |q·x − p|. Hurwitz added that infinitely many fractions satisfy |x − p/q| < 1/(√5·q²) for every irrational x, and that √5 cannot be improved, because the golden ratio [1; 1, 1, 1, …] has the smallest possible terms and therefore the slowest-improving convergents of any number. Its convergents are ratios of consecutive Fibonacci numbers, which the Fibonacci calculator lists directly: 1/1, 2/1, 3/2, 5/3, 8/5, 13/8, and so on, each one gaining only about 0.42 decimal digits.

The Best Fraction Under a Denominator Limit

Ask for the closest fraction to π with a denominator of at most 100 and 22/7 is not the answer. The convergents jump from q = 7 straight to q = 106, and between them sit the in-between fractions (3 + k × 22)/(1 + k × 7) for k = 1 to 14: 25/8, 47/15, 69/22, …, 311/99. These semiconvergents are not convergents, yet the later ones beat 22/7. The calculator compares the largest one that fits, 311/99 (k = 14), against 22/7 using exact arithmetic: 311/99 is off by 1.79 × 10⁻⁴, 22/7 by 1.26 × 10⁻³, so 311/99 wins. With the limit at 1,000 the answer flips back to a convergent, 355/113, because the biggest in-between fraction under 1,000, 2818/897, is off by 9.6 × 10⁻⁶.

The rule behind this: the k-th semiconvergent beats the previous convergent whenever k is more than half of the next term, and when k equals exactly half it has to be checked directly. Rather than trusting the rule, the tool measures both candidates against the number itself, which is why it can also report the runner-up.

Two real budgets on the denominator show why this matters. The mean tropical year is about 365.24219 days, and a calendar can only insert whole leap days into whole-year cycles. Expanding 365.24219 gives [365; 4, 7, 1, 3, 24, …], and the convergents of the fractional part are 1/4, 7/29, 8/33 and 31/128. One leap day every 4 years is the Julian rule; 8 leap days in 33 years is the cycle of the Persian Jalali calendar; 31 in 128 gives 365.2421875, closer to the true year than the Gregorian 97 in 400 (365.2425), which is a convenient cycle rather than a convergent. Set the limit to 400 in the calculator and it returns 31/128, not 97/400.

The second budget is musical. A perfect fifth is a frequency ratio of 3/2, which is log₂(3/2) = 0.5849625… of an octave. Expanding 0.5849625007 gives [0; 1, 1, 2, 2, 3, 1, 5, 2, 23, …] with convergents 1/1, 1/2, 3/5, 7/12, 24/41, 31/53 and 179/306. The 7/12 says that seven semitones out of twelve approximate a fifth to within 0.1%, which is why the twelve-note scale works at all; 41 and 53 notes per octave are the next tunings that do markedly better, and both have been built.

Square Roots Repeat: Periodic Continued Fractions

Expand √2 and the terms settle into a loop at once: [1; 2, 2, 2, …], written [1; (2)]. Every square root of a non-square integer does this, and so does every number of the form (p + m√d)/q. Lagrange proved the converse too: an expansion is eventually periodic exactly when the number is a quadratic irrational. The calculator finds the period exactly by running an integer recurrence instead of decimals. Write each stage as (P + √D)/Q; the next term is a = ⌊(P + √D)/Q⌋, and the next stage is P′ = aQ − P, Q′ = (D − P′²)/Q. For √2 the stages are (0, 1) → (1, 1) → (1, 1) …, so the first repeat appears after one step and the period is 1. The square root calculator gives the decimal value; the expansion here is exact and needs no decimals at all.

NumberExpansionPeriod
√2[1; (2)]1
√3[1; (1, 2)]2
√7[2; (1, 1, 1, 4)]4
√13[3; (1, 1, 1, 1, 6)]5
√19[4; (2, 1, 3, 1, 2, 8)]6
√61[7; (1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14)]11
(1 + √5)/2[1; (1)]1

The square roots share a shape: the block ends with 2 × a0 (2, 2, 4, 6, 8, 14 above) and everything before that last term reads the same backwards, a consequence of Galois’s theorem on purely periodic expansions. The period length is erratic, though: √61 needs 11 terms while √62 needs only 4, and there is no formula for it in terms of D. There is a payoff for the patience. The convergent just before the end of a period solves Pell’s equation p² − D·q² = ±1: for √2 the convergents 3/2, 7/5, 17/12 and 41/29 give 9 − 8 = 1, 49 − 50 = −1, 289 − 288 = 1, 1681 − 1682 = −1. For √61 the smallest solution has p = 1,766,319,049, which is why Fermat liked to pose it.

Numbers that are not quadratic never settle into a period, but some still have a pattern. Euler showed e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, …], with the even numbers marching up every third term; the calculator’s 400 digits confirm that shape for the first 278 terms. π has no known pattern at all, and its terms 3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, … are simply what the computation produces, term after term.

Turning a List of Terms Back Into a Number

To evaluate [3; 7, 15, 1] by hand, start at the bottom: 15 + 1/1 = 16, then 7 + 1/16 = 113/16, then 3 + 16/113 = 355/113. Or run the forward recurrence from the previous section and read off the last convergent; the calculator does that, which is also how it fills its table. Notice that [3; 7, 15, 1] and [3; 7, 16] are the same number. A list ending in 1 can always be absorbed into the term before it, so expansions produced by the calculator never end in 1, but it evaluates both spellings when you type them.

A repeating list takes one more idea. In [1; (2)], call the repeating part y = [2; 2, 2, …]. Then y = 2 + 1/y, so y² − 2y − 1 = 0 and y = 1 + √2. The whole number is 1 + 1/y = 1 + 1/(1 + √2) = 1 + (√2 − 1) = √2. In general the block satisfies qₘ·y² + (qₘ₋₁ − pₘ)·y − pₘ₋₁ = 0, where p and q are the convergents of the block alone, and the terms before the block map y to the final value with the same recurrence. The calculator returns the result as an exact (p + m√d)/q, then expands that surd again to confirm that it reproduces the list you typed. Contrast this with repeating decimals, which always name a fraction: 0.(3) is 1/3, and the repeating decimal to fraction calculator handles that conversion; a repeating continued fraction, by contrast, is never rational.

What a Continued Fraction Calculator Must Handle: Rounded Decimals, Negatives and Long Periods

  • Rounded input. 3.14159 expands to [3; 7, 15, 1, 25, 1, 7, 4], which is correct for the fraction 314159/100000 but says little about π. If 3.14159 is a rounded measurement, the true value lies anywhere between 3.141585 and 3.141595, and only [3; 7] is shared by that whole interval: the third step of π lands at 15.996, so a nudge of 3 × 10⁻⁷ upward turns the 15 into a 16. The calculator reports how many terms a rounded decimal guarantees. Seven decimals, 3.1415926, guarantee four terms; to see the 292 you need the π button or at least nine decimals.
  • Floating point. A double-precision number holds about 16 significant digits, so a spreadsheet loop that floors and flips π drifts into nonsense after roughly 15 terms. This page never touches floating point for the terms: fractions and decimals are exact integers, surds use the integer recurrence, and π and e are computed to 400 digits with the interval method described in the working section, which is how it can list 403 certain terms of π.
  • Negative numbers. Two conventions exist. This calculator uses the floor: −7/3 = [−3; 1, 2], because −3 + 1/(1 + 1/2) = −3 + 2/3 = −7/3. The alternative, negating the expansion of 7/3 to get −[2; 3], is common in textbooks; the floor version keeps every later term positive, which is what the convergent theorems assume.
  • Roots in the denominator. Write 1/√2 as √2/2 and (1 + √5)/2 with its parentheses; the parser accepts whole numbers only inside the root form, and a radicand up to 10¹⁵ after the coefficient is absorbed (2√3 becomes √12).
  • Long periods. The period of √D can be as long as roughly √D × ln D, so a fifteen-digit radicand may repeat only after hundreds of thousands of terms. The tool searches 100,000 terms, shows what it found exactly, and says so when the period is still open.
  • A zero after the first term. [3; 0, 2] is not a valid simple continued fraction; the calculator refuses it instead of guessing. Decimal commas and scientific notation are refused with a message for the same reason: every accepted input has one unambiguous meaning.

The definitions, the error bounds and the best-approximation theorems used here follow the treatment in Wikipedia’s simple continued fraction article; the results of Lagrange and Galois on periodicity, and the palindromic shape of √D, are set out in its periodic continued fraction article. The terms of π listed by the calculator were checked against OEIS A001203, and the year length against the J2000 mean tropical year of 365.2421897 days in Wikipedia’s tropical year article; with those seven decimals the expansion begins [365; 4, 7, 1, 3, 27, …] and five terms are certain, which is enough to confirm the 31/128 cycle.

Frequently Asked Questions

What is a continued fraction?

A continued fraction writes a number as a whole part plus one over (a whole part plus one over ...), abbreviated [a0; a1, a2, ...]. The first term a0 can be any integer and every later term is a positive integer. For example 415/93 = 4 + 1/(2 + 1/(6 + 1/7)) = [4; 2, 6, 7], and pi = [3; 7, 15, 1, 292, 1, 1, 1, 2, ...]. A fraction always gives a finite list, an irrational number never ends.

How do you convert a decimal to a continued fraction?

Take the whole part as the first term, subtract it, flip what is left, and repeat. For 3.14159 the whole part is 3 and the remainder 0.14159 flips to 7.0626..., so the next term is 7, and so on, giving [3; 7, 15, 1, 25, 1, 7, 4]. The calculator does this on the exact fraction 314159/100000, so the list is exact for that decimal. It also reports that if 3.14159 is a rounded value, only [3; 7] is certain, because the third step of pi lands at 15.996 and flips to 16 for numbers slightly above 3.1415929.

What are the convergents of a continued fraction?

Convergents are the fractions you get by cutting the list short. For pi = [3; 7, 15, 1, 292, ...] they are 3/1, 22/7, 333/106, 355/113 and 103993/33102. They come from the recurrences p(n) = a(n) p(n-1) + p(n-2) and q(n) = a(n) q(n-1) + q(n-2), and each convergent is the closest fraction to the number among all fractions whose denominator is no larger than its own.

Why is 355/113 such a good approximation of pi?

Because the term after it in the expansion of pi is 292, which is unusually large. A convergent p/q always satisfies |x - p/q| < 1/(q times the next denominator), and the next denominator is 292 x 113 + 106 = 33102, so the error must be below 1/(113 x 33102) = 2.67 x 10^-7. The actual error is 2.668 x 10^-7, giving six and a half correct decimals from a three-digit denominator. The convergent before it, 333/106, is followed by a 1 and is only accurate to 8.3 x 10^-5.

What is the continued fraction of the square root of 2, and why does it repeat?

The square root of 2 is [1; 2, 2, 2, ...], written [1; (2)] with the repeating block in parentheses. Every square root of a non-square integer repeats, for example the square root of 3 is [1; (1, 2)], the square root of 7 is [2; (1, 1, 1, 4)] and the square root of 19 is [4; (2, 1, 3, 1, 2, 8)]. Lagrange proved that an expansion repeats exactly when the number is a quadratic irrational, a root of a quadratic equation with integer coefficients. The calculator finds the period with an exact integer recurrence rather than decimals.

How do I turn [3; 7, 15, 1] back into a fraction?

Work from the bottom up: 15 + 1/1 = 16, then 7 + 1/16 = 113/16, then 3 + 16/113 = 355/113. The calculator does the same with the forward recurrence for convergents and shows every intermediate fraction. Note that [3; 7, 15, 1] and [3; 7, 16] are the same number, because a final 1 can be absorbed into the term before it. A repeating list such as [1; (2)] gives a surd instead: the block satisfies y = 2 + 1/y, so y = 1 + the square root of 2, and the whole number is the square root of 2.

How do I find the best fraction for pi with a denominator under 100?

It is 311/99, not 22/7. The convergents jump from denominator 7 to 106, and in between sit the semiconvergents (3 + 22k)/(1 + 7k) for k from 1 to 14. The largest that fits, 311/99, is off by 1.79 x 10^-4, while 22/7 is off by 1.26 x 10^-3. The calculator compares the last convergent under the limit with the largest semiconvergent under it using exact arithmetic and reports both. With the limit raised to 1000 the winner is the convergent 355/113 again.

Is the continued fraction of a number unique?

For an irrational number, yes: the floor-subtract-flip process has no choices to make. A rational number has exactly two spellings, one ending in a term of 2 or more and one ending in 1, such as [3; 7, 16] and [3; 7, 15, 1]; the calculator produces the first form. Negative numbers depend on convention: this calculator uses the floor, so -7/3 = [-3; 1, 2], while some textbooks negate the expansion of 7/3 and write -[2; 3] instead.