Continued Fraction Calculator

Convert between numbers and simple continued fractions with a beautiful nested fraction display. Compute convergents and explore the beauty of continued fractions.

Enter integers separated by commas. The first term is the integer part. Example: 1,2,2 represents [1;2,2]
1,2,2 (1.4) 2,1,2,1 (√3 ≈1.732) 1,1,1,1,1 (φ≈1.618) 3,7,15,1 (π approx)
Enter a decimal (e.g., 1.4) or fraction (e.g., 7/5). Max terms:
1.4 √3 ≈1.732 φ≈1.618 π 0.75 (3/4)
1 + 12 + 12

What Is a Continued Fraction?

A continued fraction is an expression of the form

x = a₀ + 1a₁ + 1a₂ + 1a₃ + ⋱

where a₀ is an integer (possibly negative) and a₁, a₂, a₃, ... are positive integers, called the partial quotients. Every real number can be represented uniquely as a (possibly infinite) continued fraction. For rational numbers, the expansion terminates; for irrational numbers, it continues indefinitely. This representation reveals deep structural properties of numbers and lies at the heart of the Euclidean algorithm, Diophantine approximation, and dynamical systems.

The convergents pₙ/qₙ are the rational approximations obtained by truncating the continued fraction at the n‑th term.
They satisfy: |x − pₙ/qₙ| < 1/qₙ²  — the best possible rational approximation for a given denominator size.

A Journey Through History

The origins of continued fractions trace back to the ancient Greek mathematician Euclid (c. 300 BCE), whose algorithm for finding the greatest common divisor implicitly generates the continued fraction of a rational number. The modern notation and systematic study began with Raffaele Bombelli (1572) and Pietro Cataldi (1613), who used them to approximate square roots.

In the 18th century, Leonhard Euler and Joseph-Louis Lagrange established the foundational theory. Euler showed that every rational number has a terminating continued fraction, while Lagrange proved that quadratic irrationals (like √2) have periodic continued fractions — a result that connects number theory with dynamical systems. The legendary Carl Friedrich Gauss studied continued fractions in the context of arithmetic-geometric mean and elliptic functions.

In the 20th century, continued fractions found surprising applications in cryptography (via the continued fraction algorithm for solving Pell's equation), computer science (for floating-point error analysis), and chaos theory (through the Gauss map and the study of irrational rotations). Today, they remain an active area of research in analytic number theory and dynamical systems.

Why Use an Interactive Continued Fraction Calculator?

  • Deepen Understanding: Visualize how convergents approach the target value. See the remarkable speed of convergence — often exponential — and appreciate why continued fractions provide the "best" rational approximations.
  • Educational Exploration: Test conjectures, explore the continued fractions of famous constants (π, e, φ), and discover patterns. Perfect for students of number theory, analysis, and discrete mathematics.
  • Practical Applications: Use in numerical analysis, signal processing (rational approximation), or engineering design where rational approximations are required (e.g., gear ratios, musical scales).
  • Research Tool: Quickly obtain convergents and partial quotients for further symbolic manipulation or to test hypotheses in computational number theory.

The Mathematics Behind the Calculator

Given a real number x, the continued fraction algorithm is a direct application of the Euclidean algorithm:

  1. Set a₀ = ⌊x⌋ (the integer part).
  2. Let r = x − a₀. If r = 0, stop.
  3. Otherwise, set x = 1/r and repeat.

This produces the sequence a₀, a₁, a₂, ... of partial quotients. For rational x, the process terminates after finitely many steps. For irrational x, it continues indefinitely, and the convergents pₙ/qₙ provide increasingly accurate rational approximations.

The convergents are computed recursively:

p₋₂ = 0, p₋₁ = 1,   q₋₂ = 1, q₋₁ = 0,
pₙ = aₙ·pₙ₋₁ + pₙ₋₂,   qₙ = aₙ·qₙ₋₁ + qₙ₋₂.

This recurrence ensures that pₙ/qₙ is always in lowest terms (gcd(pₙ, qₙ) = 1) and that the error satisfies the bound |x − pₙ/qₙ| < 1/(qₙ·qₙ₊₁).

Step-by-Step Usage

  1. Choose a mode: "Real → Continued Fraction" to expand a number, or "Continued Fraction → Real" to evaluate a given expansion.
  2. Enter your input: For real numbers, enter a decimal or fraction (e.g., 3.14159 or 22/7). For coefficients, enter integers in the provided fields.
  3. Set max terms (optional) — the number of partial quotients to compute.
  4. Click "Compute" to see the continued fraction, convergents, and the convergence plot.
  5. Experiment with presets to explore famous constants and their expansions.

Examples and Reference Table

The following expansions have been verified and are consistent with standard mathematical references.

Number Continued Fraction First Convergents Type
π [3; 7, 15, 1, 292, 1, 1, 1, 2, ...] 3, 22/7, 333/106, 355/113, 103993/33102 Transcendental
e [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, ...] 2, 3, 8/3, 11/4, 19/7, 87/32 Transcendental
φ (golden ratio) [1; 1, 1, 1, 1, ...] 1, 2, 3/2, 5/3, 8/5, 13/8 Algebraic (quadratic)
√2 [1; 2, 2, 2, 2, ...] 1, 3/2, 7/5, 17/12, 41/29 Algebraic (quadratic)
√3 [1; 1, 2, 1, 2, 1, 2, ...] 1, 2, 5/3, 7/4, 19/11, 26/15 Algebraic (quadratic)
0.5 [0; 2] 0, 1/2 Rational
Case Study: Musical Scales and Continued Fractions

The problem of dividing an octave into equal steps has been tackled using continued fractions since antiquity. The ratio 3/2 (perfect fifth) has continued fraction [1; 2], while the equally-tempered fifth corresponds to 2^(7/12) ≈ 1.4983, whose continued fraction begins [1; 2, 99, ...]. The convergents of 2^(7/12) reveal why the 12‑tone equal temperament works so well: the convergent 3/2 appears as the first approximation, and the next convergent provides an even better ratio. This interplay between music theory and continued fractions was explored by Euler and later by mathematicians such as Helmholtz and Ellis. Our calculator lets you explore these ratios interactively — simply enter the decimal value of a musical interval and observe its continued fraction expansion.

The Gauss–Kuzmin–Wirsing Distribution

For a random real number in (0,1), the probability that its continued fraction has partial quotient aₙ = k is given by the Gauss–Kuzmin distribution:

P(k) = log₂(1 + 1/(k(k+2))).

This remarkable result, discovered by Gauss and later proved by Kuzmin (1928) and Lévy (1929), shows that the partial quotients of almost all real numbers are not arbitrary but follow a specific statistical law. The Wirsing constant refines the convergence rate of this distribution. Our tool can be used to generate empirical distributions of partial quotients for user‑supplied numbers, illustrating this deep connection between number theory and probability.

Common Misconceptions

  • "Continued fractions are only for rational numbers." — False. Every real number has a continued fraction expansion; rational numbers have finite expansions, while irrational numbers have infinite expansions.
  • "The convergents always alternate around the target." — True. For simple continued fractions, convergents strictly alternate: even-indexed convergents are below the target, odd-indexed are above (or vice versa, depending on the sign).
  • "The Euclidean algorithm and continued fractions are unrelated." — False. The Euclidean algorithm for integers is exactly the process of generating the continued fraction of a rational number.
  • "All continued fractions are simple (all numerators are 1)." — The calculator uses simple continued fractions (with numerators equal to 1), which are the most common and mathematically well‑studied form. Generalized continued fractions allow other numerators but are beyond the scope of this tool.

Applications Across Disciplines

  • Cryptography: Continued fractions are used in algorithms for solving Pell's equation, which underpins some public‑key cryptosystems.
  • Numerical Analysis: Rational approximations from continued fractions are used in floating‑point implementations of elementary functions (sin, cos, exp, log).
  • Physics: The renormalization group in statistical mechanics uses continued fractions to study critical phenomena.
  • Computer Graphics: Continued fractions appear in the study of low‑discrepancy sequences and quasi‑Monte Carlo methods.
  • Music Theory: As noted above, continued fractions model the convergence of musical intervals to rational ratios.

Rooted in classical and modern mathematics – This tool is built upon the foundational work of Euclid, Euler, Lagrange, and Gauss, and incorporates modern computational number theory. The implementation follows algorithms verified against authoritative sources (Hardy & Wright, "An Introduction to the Theory of Numbers"; Khinchin, "Continued Fractions"; and the OEIS). The interactive visualization uses standard Canvas rendering and is reviewed by the GetZenQuery tech team. Last updated June 2026.

Frequently Asked Questions

In a simple continued fraction, all numerators are 1. The expression is written as [a₀; a₁, a₂, a₃, ...]. In a generalized continued fraction, numerators can be arbitrary numbers. This calculator uses simple continued fractions, which are the classical and most widely studied form.

If an irrational number had a finite continued fraction, it would be rational (since finite continued fractions evaluate to rational numbers). Therefore, irrational numbers necessarily have infinite continued fraction expansions. The converse is also true: every infinite continued fraction converges to an irrational number.

The convergents are the best rational approximations to the target number in the sense that |x − p/q| < 1/q² for every convergent p/q. Moreover, no rational number with denominator ≤ q can approximate x better than the convergent pₙ/qₙ. This is known as the Legendre theorem and is a cornerstone of Diophantine approximation.

Yes. For a negative number, a₀ will be the integer part (floor) which is negative or zero, and the remaining partial quotients a₁, a₂, ... are still positive integers. For example, −π = [−4; 1, 6, 15, 1, 292, ...].

The calculator recognizes fractions in the form "a/b" and evaluates them as floating‑point numbers. The continued fraction of 22/7 is [3; 7] — a finite expansion, since it's rational. The convergents will match the original value exactly after the final term.

Excellent resources include Wolfram MathWorld, the classic book "Continued Fractions" by A. Ya. Khinchin, and "An Introduction to the Theory of Numbers" by Hardy and Wright. For a more accessible introduction, try the Khan Academy lessons on rational expressions and the Euclidean algorithm.
References: MathWorld: Continued Fraction; Khinchin, A. Ya. "Continued Fractions" (1964); Hardy, G. H. & Wright, E. M. "An Introduction to the Theory of Numbers" (6th ed., 2008); Wikipedia: Continued Fraction.