Skip to main content

Continued Fractions Calculator

Convert numbers to continued fraction representation and calculate convergents

Category: Mathematics

Continued Fractions Calculator Inputs

Enter values to calculate

Enter the Number (decimal or fraction) text used by the Continued Fractions Calculator.

Enter the Maximum Terms value used by the Continued Fractions Calculator.

Enable JavaScript for interactive calculation and step-by-step results.

Continued Fractions Calculator Formula

Equation

x = a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + ...)))

Excel Formula

=x=a₀+1/(a₁+1/(a₂+1/(a₃+...))

Variables

  • Number (decimal or fraction) — Enter the Number (decimal or fraction) text used by the Continued Fractions Calculator.
  • Maximum Terms — Enter the Maximum Terms value used by the Continued Fractions Calculator.

How the Continued Fractions Calculator Works

Continued fractions provide a unique and powerful way to represent real numbers as nested fractions of the form a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + ...))). This representation has remarkable properties: it gives the "best" rational approximations to irrational numbers in a precise sense, reveals patterns in numbers (like the elegant [1;1,1,1,...] for the golden ratio), and appears naturally in number theory, dynamical systems, and even quantum mechanics. Unlike decimal expansions which can be arbitrary and obscure patterns, continued fractions often expose deep mathematical structure. The Euclidean algorithm for finding GCD is essentially the continued fraction algorithm in disguise. Convergents (truncated continued fractions) provide increasingly accurate rational approximations, making them invaluable for fraction calculations, calendar design, gear ratios, and numerical computations.

The core relationship is x = a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + ...))). Typical inputs include Number (decimal or fraction), Maximum Terms.

Enter your values in the continued fractions calculator above, review the step-by-step solution, and compare against the worked examples below so you can see how each input changes the result. This free online mathematics tool is built for homework, design checks, and professional verification.

Continued Fractions Calculator Theory & Explanation

Definition and Notation

A continued fraction represents a real number x as: x = a_0 + \cfrac1a_1 + \cfrac1a_2 + \cfrac1a_3 + ·s where a_0 is an integer (the integer part) and a_1, a_2, ... are positive integers. Compact notation: x = [a_0; a_1, a_2, a_3, ...]. For finite continued fractions (rational numbers), x = [a_0; a_1, ..., a_n]. For infinite continued fractions (irrational numbers), the sequence continues forever. The algorithm to compute continued fraction representation is the Euclidean algorithm: take integer part, invert remainder, repeat. Every rational number has a finite continued fraction; every irrational has an infinite one. Periodic continued fractions (eventually repeating pattern) represent quadratic irrationals like √(2) = [1; 2, 2, 2, ...].

x = a_0 + \cfrac1a_1 + \cfrac1a_2 + \cfrac1a_3 + ·s

Computing Continued Fractions

The algorithm for finding the continued fraction of x is straightforward. Step 1: a_0 = \lfloor x \rfloor (integer part). Step 2: If x = a_0 (integer), stop. Otherwise, compute r_0 = x - a_0 (fractional part). Step 3: Set x_1 = 1/r_0 and a_1 = \lfloor x_1 \rfloor. Step 4: Repeat with x_2 = 1/(x_1 - a_1), and so on. For example, π ≈ 3.14159: a_0 = 3, x_1 = 1/0.14159 = 7.063, a_1 = 7, x_2 = 1/0.063 = 15.996, a_2 = 15, giving π ≈ [3; 7, 15, 1, ...]. This algorithm terminates for rational numbers and continues indefinitely for irrationals. The connection to the Euclidean algorithm is profound: finding \gcd(a,b) uses the same sequence of divisions.

a_n = \lfloor x_n \rfloor, \quad x_n+1 = (1)/(x_n - a_n)

Convergents and Best Approximations

The n-th convergent is the rational number obtained by truncating the continued fraction after n terms: C_n = [a_0; a_1, ..., a_n] = (p_n)/(q_n) Convergents can be computed recursively: p_-1=1, p_0=a_0, and p_n = a_n p_n-1 + p_n-2. Similarly for denominators: q_-1=0, q_0=1, and q_n = a_n q_n-1 + q_n-2. Remarkably, convergents are the best rational approximations in a precise sense: if |x - p/q| < |x - p_n/q_n| for some p/q, then q > q_n. In other words, convergents give the most accurate approximation for a given denominator size. This makes them optimal for applications like fraction approximations, musical intervals, gear ratios, and calendar systems (e.g., 365/366 day year fractions).

p_n = a_n p_n-1 + p_n-2, \quad q_n = a_n q_n-1 + q_n-2

Periodic Continued Fractions

A continued fraction is eventually periodic if its sequence of partial quotients repeats from some point onward: x = [a_0; a_1, ..., a_k, \overlineb_1, ..., b_m] where the overline indicates repetition. A fundamental theorem states that x has an eventually periodic continued fraction if and only if x is a quadratic irrational (solution to ax^2 + bx + c = 0 with integer coefficients and x irrational). For example, √(2) = [1; \overline2] (purely periodic), √(7) = [2; \overline1,1,1,4], and the golden ratio \phi = [1; \overline1] (the simplest infinite continued fraction). This characterization connects continued fractions deeply to algebraic number theory and Pell's equation.

√(2) = [1; \overline2], \quad \phi = [1; \overline1]

Properties and Inequalities

Continued fractions satisfy beautiful inequalities. Convergents alternate around the true value: C_0 < C_2 < C_4 < ·s < x < ·s < C_5 < C_3 < C_1 (for x > 0). The error in approximation satisfies: (1)/(q_n(q_n+1) + q_n) < |x - (p_n)/(q_n)| < (1)/(q_n q_n+1) This bounds how good the approximation is. Consecutive convergents satisfy: p_n q_n-1 - p_n-1q_n = (-1)^n-1, implying \gcd(p_n, q_n) = 1 (convergents are always in lowest terms). These properties make continued fractions powerful for proving irrationality, finding Diophantine approximations, and analyzing dynamical systems.

(1)/(q_n(q_n+1) + q_n) < |x - (p_n)/(q_n)| < (1)/(q_n q_n+1)

Golden Ratio and Fibonacci Connection

The golden ratio \phi = (1+√(5))/2 has the simplest infinite continued fraction: \phi = [1; 1, 1, 1, 1, ...] = 1 + \cfrac11 + \cfrac11 + \cfrac11 + ·s Its convergents C_n = F_n+1/F_n are ratios of consecutive Fibonacci numbers: 1/1, 2/1, 3/2, 5/3, 8/5, 13/8, ..., which approach \phi as n \to ∞. This connection explains why Fibonacci ratios appear in nature (phyllotaxis, spiral patterns)—they provide optimal packing. The slow convergence of \phi (all partial quotients are 1, the smallest possible) makes it the "most irrational" number, hardest to approximate by rationals. This has applications in dynamical systems: perturbations with frequencies in golden ratio avoid resonances, explaining its appearance in planetary orbits and atomic spectra.

\phi = [1; \overline1], \quad C_n = \fracF_n+1F_n \to \phi

Applications and Computational Uses

Continued fractions have numerous applications. In computer arithmetic, they provide exact fraction representation (unlike floating point). Calendar design uses continued fractions: the year length 365.2422 days = [365; 4, 7, 1, 3, 4, ...] gives the Gregorian calendar (convergent 365 + 97/400 = 365.2425 days, accurate to 1 day/3300 years). Gear ratio design uses convergents for fractional speed ratios with small gears. Numerical analysis uses continued fractions to evaluate functions and solve equations (Gauss continued fractions for hypergeometric functions). In quantum chaos, continued fraction expansion of rotation numbers characterizes quasiperiodic motion. The Lenstra elliptic curve factorization algorithm uses continued fractions for integer factorization. They appear in moment problem solutions, Padé approximants, and orthogonal polynomials.

\textApplications: fraction arithmetic, calendars, gears, numerical analysis, chaos theory

Continued Fractions Calculator Worked Examples

Worked Example

Inputs

  • numberInput: 3.14159
  • maxTerms: 5

Result: [3; 7, 15, 1, 292] ≈ 355/113

Explanation

π ≈ 3.14159 has continued fraction [3;7,15,1,292,...]; convergent 355/113 is accurate to 6 decimal places

Golden Ratio

Inputs

  • numberInput: 1.618034
  • maxTerms: 8

Result: [1; 1, 1, 1, 1, 1, 1, 1]

Explanation

φ = (1+√5)/2 has all partial quotients equal to 1, the simplest infinite continued fraction

Common Continued Fractions Calculator Use Cases

  • Homework and exam practice
  • Engineering and science coursework
  • Quick verification of hand calculations
  • Continued Fractions homework and study
  • Continued Fractions design and analysis

Continued Fractions Calculator FAQs

What is a continued fraction and why is it useful?

A continued fraction writes a number as a₀ + 1/(a₁ + 1/(a₂ + ...)), denoted [a₀; a₁, a₂, ...]. It's useful because it gives the best rational approximations—for a given denominator size, no other fraction is closer to the target number. This makes continued fractions ideal for finding simple fractions that approximate irrationals like π or √2. They also reveal patterns: the golden ratio is [1;1,1,1,...], √2 is [1;2,2,2,...]. Applications include calendar design, gear ratios, music theory, and numerical analysis.

How do I convert a number to a continued fraction?

Start with your number x. Step 1: Take the integer part a₀ = ⌊x⌋. Step 2: If x is an integer, stop. Otherwise, compute x₁ = 1/(x-a₀). Step 3: Take a₁ = ⌊x₁⌋. Step 4: Repeat: x₂ = 1/(x₁-a₁), a₂ = ⌊x₂⌋, etc. For example, π: a₀=3, x₁=1/0.14159...=7.06..., a₁=7, x₂=1/0.06...=15.99..., a₂=15, giving π≈[3;7,15,...]. The algorithm terminates for rationals and continues indefinitely for irrationals. This is exactly the Euclidean algorithm in disguise.

What are convergents and why are they "best" approximations?

Convergents are the fractions pₙ/qₙ obtained by truncating the continued fraction after n terms. They're "best" approximations because they minimize error for a given denominator size—no fraction with smaller or equal denominator is closer to the true value. For π: convergents are 3/1, 22/7, 333/106, 355/113, ... The famous 22/7 and 355/113 are convergents, explaining their exceptional accuracy. Convergents satisfy pₙqₙ₋₁ - pₙ₋₁qₙ = ±1, ensuring they're in lowest terms. This optimality makes them ideal for practical approximations.

How do I calculate convergents?

Use the recursion formulas starting with p₋₁=1, p₀=a₀, q₋₁=0, q₀=1. For n≥1: pₙ = aₙpₙ₋₁ + pₙ₋₂ and qₙ = aₙqₙ₋₁ + qₙ₋₂. For golden ratio [1;1,1,1,...]: p₀/q₀=1/1, p₁/q₁=(1·1+1)/(1·1+0)=2/1, p₂/q₂=(1·2+1)/(1·1+1)=3/2, p₃/q₃=5/3, giving Fibonacci ratios 1/1, 2/1, 3/2, 5/3, 8/5, 13/8, ... Notice numerators and denominators follow the Fibonacci recurrence! This simple recursion generates best approximations efficiently without complex arithmetic.

Why is the golden ratio [1;1,1,1,...]?

The golden ratio φ = (1+√5)/2 satisfies φ = 1 + 1/φ. Substituting repeatedly: φ = 1 + 1/(1 + 1/φ) = 1 + 1/(1 + 1/(1 + 1/φ)) = ..., giving [1;1,1,1,...]. All partial quotients are 1 (the smallest possible), making φ the "most irrational" number—hardest to approximate by rationals. Its convergents Fₙ₊₁/Fₙ converge slowest among all irrationals. This property explains φ's appearance in optimization (golden section search), phyllotaxis (plant spirals avoid rational resonances), and art (pleasing proportions resist simple fraction simplification).

What patterns do square roots have?

Square roots of non-perfect squares have periodic continued fractions. √2 = [1;2,2,2,...] (period 1), √3 = [1;1,2,1,2,1,2,...] (period 2), √5 = [2;4,4,4,...] (period 1), √7 = [2;1,1,1,4,1,1,1,4,...] (period 4). The periodicity reflects the quadratic nature. For √N where N not a perfect square, the continued fraction is eventually periodic. Conversely, any eventually periodic continued fraction represents a quadratic irrational. This characterization is powerful in algebraic number theory and relates to Pell's equation solutions.

How are continued fractions used in calendar design?

A year is about 365.2422 days. Its continued fraction [365;4,7,1,3,4,...] gives convergents: 365/1 (poor), 1461/4 = 365.25 (Julian calendar, 4-year cycle with leap years), 8/33 correction gives Gregorian (365.2425, accurate to 1 day/3300 years). The Gregorian rule (leap year every 4 years except century years unless divisible by 400) comes from this convergent. Hebrew and Islamic calendars use different convergents for their lunar/solar ratios. Continued fractions provide systematic way to balance simplicity (small denominators) against accuracy.

Can I do arithmetic with continued fractions?

Arithmetic is possible but complex. Addition [a;...] + [b;...] doesn't have simple formula—you must convert to fractions, add, then convert back. Multiplication and division are similarly complicated. However, special operations exist: reciprocal of [a₀;a₁,a₂,...] is [0;a₀,a₁,a₂,...] (prepend 0). Adding 1: [a₀;a₁,...] + 1 = [a₀+1;a₁,...]. For efficient exact arithmetic with rationals, continued fractions have advantages over decimals (exact representation, automatic simplification), but require more sophisticated algorithms than standard fraction arithmetic.