Continued Fraction Calculator

Convert decimals and fractions to simple continued fractions [a0; a1, a2, ...] and back. Enter a decimal (e.g. 3.14159), a fraction (22/7), or a continued fraction ([3;7,15,1,292]). Toggle "Show Steps" to see the Euclidean algorithm breakdown for rational inputs.

Continued fractions: theory, convergents and best approximations

Continued fractions provide a powerful and classical way to represent real numbers. Unlike decimal expansions, continued fractions often reveal inherent Diophantine structure and produce the best rational approximations for their length. In this article we explore simple continued fractions, how they are computed, connections to the Euclidean algorithm, and why truncations (convergents) are often the optimal rational approximations to irrational numbers.

Simple continued fractions and convergents

A simple continued fraction has integer partial quotients and the nested form [a0; a1, a2, ...] = a0 + 1/(a1 + 1/(a2 + ...)). Convergents are rational approximations obtained by truncating the continued fraction after k terms. If p_k/q_k is the kth convergent, they satisfy recurrence relations p_k = a_k p_{k−1} + p_{k−2}, q_k = a_k q_{k−1} + q_{k−2} with initial values p_{−2}=0, p_{−1}=1, q_{−2}=1, q_{−1}=0.

Euclidean algorithm connection

For rational numbers p/q, performing the Euclidean algorithm (repeated integer division to find quotients and remainders) directly yields the partial quotients of the continued fraction. This close link explains why continued fractions terminate for rationals: the Euclidean algorithm terminates when the remainder becomes zero.

Why convergents are best approximations

One of the key theorems is that convergents give the best approximations in the sense that any rational r with denominator ≤ q_k cannot approximate the target number better than p_k/q_k. This property makes continued fractions fundamental in Diophantine approximation and helps explain the exceptional quality of approximations like 355/113 for π.

Periodic continued fractions and quadratic irrationals

Quadratic irrational numbers (roots of quadratic equations with integer coefficients) have eventually periodic continued fraction expansions. For example, √2 = [1; 2,2,2,...]. This periodicity ties directly into number theory and Pell equations.

Computation and rounding

Converting decimals to continued fractions requires deciding when to stop for irrational inputs; we allow a maximum number of terms to produce truncated expansions. Rational inputs are converted exactly by using fraction parsing and the Euclidean algorithm. Numeric stability is generally good because operations are integer-based for rationals; for decimal inputs use enough precision to avoid early truncation artifacts.

Applications

Continued fractions appear in approximation theory, cryptography (Lattice attacks use continued fraction approximations), computational number theory, and dynamical systems. They also serve as analytic tools: the continued fraction of e and π reveal interesting numerical structures and provide rapidly converging approximations.

Use this calculator to experiment with conversions, study Euclidean steps for rational inputs, and generate convergents for rational approximation problems.

Frequently Asked Questions

1. How do I enter a continued fraction?
Use bracket notation like [3;7,15,1,292] or comma-separated without brackets; the tool accepts common formats.
2. What does 'Show Steps' do?
It displays the Euclidean algorithm divisions and remainders used when converting rational inputs to continued fractions.
3. Can I get best rational approximations?
Yes — convergents from truncated continued fractions give best approximations for their denominator sizes.
4. Why does 22/7 appear for π?
22/7 is the convergent from the continued fraction [3;7] and is a good approximation to π with small denominator.
5. Are negative numbers supported?
Yes — negative values are handled with standard continued-fraction conventions (sign on a0 or via simple adjustments).
6. How accurate are decimal→CF conversions?
Accuracy depends on decimal precision and max terms; higher precision yields better expansions for irrationals.
7. Can I convert CF back to fraction exactly?
Yes — finite continued fractions correspond to exact rationals and the tool will return the exact fraction and decimal.
8. What are periodic continued fractions?
They repeat after some point and correspond to quadratic irrationals (like √2) with a repeating pattern.
9. Is the tool free?
Yes — AkCalculators provides it free for education and exploration.
10. Can I export the steps?
Yes — when 'Show Steps' is enabled the Euclidean steps are shown and included in CSV exports.