Logo

MonoCalc

/

Continued Fraction Calculator

Math
Decimals, fractions such as 19/7, or the constants pi, e, phi and sqrt(n).

Try:

Continued fraction of π ≈ 3.141592653590

[3; 7, 15, 1, 292, …]

5 termsNon-terminating

Stopped early: the convergent already sits inside the chosen tolerance.

Last convergent

103993/33102

= 3.141593 · error 5.779e-10

Best approximation within tolerance

103993/33102

= 3.141593 · error 5.779e-10

Nested form

3 +
1
7 +
1
15 +
1
1 +
1
292

[3; 7, 15, 1, 292, …]

Convergents

kaₖpₖ/qₖDecimalErrorError scale
03
3/1
3.0000000.142
17
22/7
3.1428570.00126
215
333/106
3.1415098.322e-5
31
355/113
3.1415932.668e-7
4292
103993/33102Best
3.1415935.779e-10

About This Tool

Continued Fraction Calculator – Partial Quotients and Convergents

A continued fraction rewrites a number as a whole part plus one divided by another whole part plus one divided by another, and so on: a0 + 1/(a1 + 1/(a2 + …)). Mathematicians write that chain compactly as [a0; a1, a2, a3, …]. This calculator works in both directions — it expands any number, fraction or constant into its partial quotients, and it folds a list of partial quotients back into the exact fraction it represents.

How the Expansion Works

The forward algorithm is the Euclidean algorithm in disguise. Take the floor of your value to get a0, subtract it, invert what is left, and repeat. For an exact fraction the arithmetic stays in whole numbers: 19/7 gives 19 = 2×7 + 5, then 7 = 1×5 + 2, then 5 = 2×2 + 1, then 2 = 2×1 + 0, so 19/7 = [2; 1, 2, 2]. The remainder reaching zero is the whole story of termination: a simple continued fraction stops if and only if the number is rational.

Convergents Are Best Rational Approximations

Cutting the expansion off after k terms produces a convergent pk/qk, generated by the recurrence pk = ak·pk-1 + pk-2 and qk = ak·qk-1 + qk-2. Convergents are not merely close, they are optimal: no fraction with a denominator up to qk comes nearer the target. That is why the convergents of π run 3/1, 22/7, 333/106, 355/113 — and why 355/113, known in China as Zu Chongzhi's ratio since the fifth century, still beats every fraction with a denominator below 16,000.

Reading a Large Partial Quotient

A big term signals an unusually good approximation just before it. π expands to [3; 7, 15, 1, 292, …], and the jump to 292 is exactly why the preceding convergent 355/113 is accurate to seven decimal places. The same reasoning drives practical design work: gear trains, camera timing belts and calendar rules all need a simple ratio close to an awkward target, and the convergents table hands you the whole shortlist ordered by complexity.

Periodic Expansions and Quadratic Irrationals

The square root of a non-square integer always produces an eventually repeating pattern — Lagrange proved this in 1770. The calculator uses the exact integer recurrence on the triples (m, d, a) rather than floating-point division, so it can identify the repeating block precisely: √2 = [1; 2, 2, 2, …], displayed with a bar over the repeating 2, and √13 = [3; 1, 1, 1, 1, 6, …] with a five-term block. The golden ratio is the extreme case, φ = [1; 1, 1, 1, …], whose all-ones expansion makes it the hardest number of all to approximate by fractions.

Typing a decimal is not the same as typing the constant
A decimal such as 3.14159265 is treated as the exact rational 314159265/100000000, so its expansion tracks π for four terms and then diverges. Enter the keywords pi, e, phi or sqrt(n) when you want the constant itself.

Reverse Mode and Exact Arithmetic

Given 3, 7, 15, 1, 292, reverse mode folds the expression from the last term backward — x = a_n, then x = a_i + 1/x — and returns 103993/33102, already in lowest terms. Every numerator and denominator here is computed with big-integer arithmetic, so convergent denominators can run to dozens of digits without a single rounding error. Only the first partial quotient may be zero or negative; every later term must be a positive integer, which is what makes the representation essentially unique.

Controls Worth Knowing

Max terms caps how deep an irrational expansion runs, while tolerance stops it as soon as a convergent is close enough — set it to 1e-6 and π stops at 355/113. The terms slider redraws the nested fraction diagram and trims the convergents table, which makes it easy to watch the approximation error shrink term by term before exporting the table as CSV.

Frequently Asked Questions

Is the Continued Fraction Calculator free?

Yes, Continued Fraction Calculator is totally free :)

Can I use the Continued Fraction Calculator offline?

Yes, you can install the webapp as PWA.

Is it safe to use Continued Fraction Calculator?

Yes, any data related to Continued Fraction Calculator only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

How does this continued fraction calculator work?

In forward mode it takes the whole part of your value, inverts what is left over, and repeats — the same division-and-remainder loop as the Euclidean algorithm. Each whole part becomes a partial quotient a₀, a₁, a₂, …, and the convergents are built from those with the recurrence pₖ = aₖ·pₖ₋₁ + pₖ₋₂ and qₖ = aₖ·qₖ₋₁ + qₖ₋₂. In reverse mode it folds a list of partial quotients from the last term backwards to rebuild the exact fraction.

What is a convergent and why is 355/113 special?

A convergent is the fraction you get by cutting the continued fraction off after k terms. Every convergent is a best rational approximation: no fraction with a smaller denominator is closer to the target. Because π = [3; 7, 15, 1, 292, …] has an unusually large term 292 at position four, the convergent just before it — 355/113 — is extraordinarily accurate, matching π to about 2.7 × 10⁻⁷.

Why does the square root of 2 repeat forever?

Square roots of non-square integers are quadratic irrationals, and Lagrange proved that their simple continued fractions are eventually periodic. The calculator uses the exact integer (m, d, a) recurrence rather than floating-point arithmetic, so it can detect the exact repeating block: √2 = [1; 2, 2, 2, …] is shown as [1; (2)] and √7 as [2; (1, 1, 1, 4)].

Why does entering 3.14159265 give different terms than entering pi?

A typed decimal is treated as the exact rational it represents — 3.14159265 is 314159265/100000000, not π. Its expansion agrees with π for the first few terms and then diverges, which is why the fifth term becomes 288 instead of 292. Enter the keyword pi, e, phi or sqrt(n) when you want the constant itself expanded from a 50-digit internal value.

Does a terminating expansion prove a number is rational?

Yes. A simple continued fraction terminates if and only if the value is rational, which is exactly what happens when the Euclidean remainder reaches zero. Irrational values never terminate, so the calculator stops at your Max Terms limit, at your tolerance, or where its internal 50-digit precision runs out — whichever comes first.

How accurate are the convergents shown in the table?

Numerators and denominators are computed with exact big-integer arithmetic, so no digits are lost no matter how large they grow. For exact fractions the reported error is exact too. For irrational inputs the error is measured against a 50-digit approximation, so any value below roughly 10⁻⁴⁵ should be read as "smaller than the tool can resolve" rather than as a precise figure.