Continued Fraction Calculator
Convert decimals, rational fractions, square roots, and math constants into simple continued fractions. Shows step-by-step convergents and LaTeX mathematical representation.
What is a Continued Fraction?
A continued fraction is an expression obtained through an iterative process of representing a number as the sum of its integer part and the reciprocal of another number, then writing this other number as the sum of its integer part and another reciprocal, and so on. A simple continued fraction takes the following nested mathematical form:
$$x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \dots}}}$$Where $a_0$ is an integer, and all subsequent coefficients $a_i$ are positive integers (called partial quotients). It is often written compactly in bracket notation as $[a_0; a_1, a_2, a_3, \dots]$.
Rational vs. Irrational Numbers
Continued fractions provide a unique and elegant way to characterize numbers. For related conversions, try the Fraction to Decimal Calculator or explore the Golden Ratio Calculator:
- Rational Numbers: Any rational number (e.g. $\frac{22}{7}$ or finite decimals like $0.125$) has a finite continued fraction expansion that terminates (ends with a remainder of zero). This is computed using the Euclidean division algorithm.
- Irrational Numbers: Any irrational number (like $\sqrt{2}$, $\pi$, or $e$) has an infinite continued fraction expansion.
- Quadratic Irrationals: Square roots (like $\sqrt{7}$) have infinite expansions that eventually become periodic (the partial quotients repeat in a loop). For example, $\sqrt{7} = [2; 1, 1, 1, 4, 1, 1, 1, 4, \dots]$.
- Transcendental Constants: Constants like $\pi$ have non-periodic, chaotic expansions: $\pi = [3; 7, 15, 1, 292, 1, 1, 1, 2, \dots]$, whereas $e$ has a structured, non-periodic pattern: $e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, \dots]$.
Convergents Formulas
The approximations obtained by cutting off the continued fraction expansion at step $k$ are called convergents, denoted as $p_k / q_k$. They are calculated recursively from the coefficients $a_k$:
$$p_k = a_k p_{k-1} + p_{k-2}$$ $$q_k = a_k q_{k-1} + q_{k-2}$$With starting conditions: $p_{-2} = 0, p_{-1} = 1$ and $q_{-2} = 1, q_{-1} = 0$. Convergents represent the "best rational approximations" to the target real number, meaning no other fraction with a smaller denominator can be closer to the number.
Frequently Asked Questions
Why are continued fractions useful?
Continued fractions are incredibly useful in number theory and computer science because they find the absolute best rational approximations (fractions) for any real number. They are used in cryptography (e.g., Wiener's attack on RSA) and in gear ratio designs.
What is the Golden Ratio's continued fraction expansion?
The Golden Ratio $\phi \approx 1.6180339887...$ has the simplest continued fraction expansion: $[1; 1, 1, 1, 1, \dots]$. Because all coefficients are the smallest possible integer (1), it converges slower than any other number, which is why mathematicians refer to the Golden Ratio as the "most irrational" number.
Why do square roots have repeating periods?
According to Lagrange's Continued Fraction Theorem, a real number has a periodic continued fraction if and only if it is a quadratic irrational (a solution to a quadratic equation with rational coefficients). This makes finding continued fractions for roots highly predictable.