Continued Fraction Calculator
Continued fraction calculator for real and rational numbers. Convert decimals and fractions to simple continued fractions, compute convergents, and get best rational approximations step-by-step.
Full original guide (expanded)
Continued Fraction Calculator
Convert decimals and rational numbers to simple continued fractions, compute convergents, and see best rational approximations step-by-step.
Interactive continued fraction expansion and convergents
Choose how you want to define your number and what you want to compute. The tool supports:
- Decimal or rational input \((p/q)\) with controlled depth and tolerance.
- Simple continued fraction expansion \([a_0; a_1, \dots, a_n]\).
- Convergents table with \((p_k, q_k)\), decimal values, and errors.
- Reverse conversion from a continued fraction back to a number.
Limit the length of the continued fraction expansion.
Stop when the approximation error is below this tolerance.
What is a continued fraction?
A continued fraction represents a number as a nested sequence of integer parts and reciprocals. A simple continued fraction has the form
\(x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \dots}}}\)
and is usually written in compact notation as \([a_0; a_1, a_2, a_3, \dots]\). For simple continued fractions, \(a_0\) is an integer (possibly negative) and all other \(a_i\) are positive integers.
Every rational number has a finite simple continued fraction expansion, and every irrational number has an infinite one. Many classical constants have beautiful continued fractions; for example \(\sqrt{2} = [1; \overline{2}]\) and \(\varphi = [1; \overline{1}]\) (the golden ratio).
Convergents: best rational approximations
Truncating a continued fraction after \(n\) terms gives a rational number called the n-th convergent. If
\(x = [a_0; a_1, a_2, \dots]\),
then the convergents \(p_n / q_n\) are defined recursively by
\(p_{-2} = 0, \; p_{-1} = 1,\quad p_n = a_n p_{n-1} + p_{n-2},\)
\(q_{-2} = 1, \; q_{-1} = 0,\quad q_n = a_n q_{n-1} + q_{n-2}.\)
The convergents satisfy remarkable best approximation properties: for each denominator size, no other fraction gives a significantly closer approximation to the original number.
From decimal or fraction to continued fraction
The expansion of a real number \(x\) into a simple continued fraction is based on repeatedly removing the integer part and inverting the remainder:
- Set \(x_0 = x\) and \(a_0 = \lfloor x_0 \rfloor\).
- Compute the remainder \(r_0 = x_0 - a_0\).
- If \(r_0 = 0\), stop. Otherwise, set \(x_1 = 1 / r_0\) and \(a_1 = \lfloor x_1 \rfloor\).
- Repeat with \(x_2 = 1 / (x_1 - a_1)\), and so on.
For rational numbers, this process terminates after finitely many steps and is equivalent to the Euclidean algorithm for the fraction’s numerator and denominator.
From continued fraction back to a number
Given a finite list of integers \([a_0; a_1, \dots, a_n]\), you can evaluate it by starting at the end and working backwards:
Let \(x_n = a_n\), and for \(k = n-1, \dots, 0\) define \(x_k = a_k + 1/x_{k+1}\).
Then the value is \(x_0\).
This is what the calculator does in “continued fraction → number” mode, also recovering the convergents via the standard recurrence relations.
Why continued fractions matter
- Number theory: Diophantine approximation, Pell equations, and structure of quadratic irrationals.
- Numerical analysis: Stable evaluation of certain functions and special functions.
- Approximation: High-quality rational approximations for constants such as π and e.
- Algorithmic insight: A different viewpoint on the Euclidean algorithm and gcd computations.
Continued fractions – FAQ
Do continued fractions give the “best” approximations?
In a precise sense, yes: convergents of the simple continued fraction of a real number provide excellent rational approximations and satisfy strong optimality properties among fractions with bounded denominators.
Can different continued fractions represent the same rational?
A rational number has a unique simple continued fraction expansion if you require the last term to be greater than 1. Without that convention, there are two closely related finite expansions (one ends with …, an, 1, the other with …, an + 1).
How many terms do I need?
It depends on your required accuracy. The calculator lets you set a maximum depth and a tolerance on the decimal error. In practice, only a handful of terms already give excellent approximations for many constants and measurements.
Can the partial quotients be negative?
In simple continued fractions, all coefficients except possibly a0 are positive. More general continued fractions allow other choices, but the simple case already covers the core applications in number theory and rational approximation.
Is this calculator suitable for proofs and formal work?
It is primarily an exploratory and educational tool. It can strongly support intuition, checking conjectures, and drafting examples, but a formal proof would still require a rigorous argument beyond numerical output.
Frequently Asked Questions
How accurate is this continued fraction calculator?
For rational inputs p/q, the continued fraction is exact and terminates. For decimal inputs, accuracy is limited by floating-point arithmetic, the depth you allow, and the tolerance you choose. The tool reports the final approximation error so you can judge if it is adequate for your use case.
What kind of inputs should I avoid?
Avoid extremely large integers, wildly ill-conditioned decimals, or strings that are not valid numbers. The calculator also limits the number of terms to prevent runaway expansions when the pattern is long or when the tolerance is very strict.
Can I use this to recognise known constants?
Sometimes. If your decimal input is close to a famous constant (like π, e, or √2) and you see a familiar continued fraction pattern, that can be a strong hint. However, recognition should be supported by analytic arguments, not just numerical pattern matching.
Formula (LaTeX) + variables + units
','\
/g, '').replace(/
\(x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \dots}}}\)
\(x = [a_0; a_1, a_2, \dots]\),
\(p_{-2} = 0, \; p_{-1} = 1,\quad p_n = a_n p_{n-1} + p_{n-2},\) \(q_{-2} = 1, \; q_{-1} = 0,\quad q_n = a_n q_{n-1} + q_{n-2}.\)
Let \(x_n = a_n\), and for \(k = n-1, \dots, 0\) define \(x_k = a_k + 1/x_{k+1}\). Then the value is \(x_0\).
- PMI = private mortgage insurance (monthly) (currency)
- NIST — Weights and measures — nist.gov · Accessed 2026-01-19
https://www.nist.gov/pml/weights-and-measures - FTC — Consumer advice — consumer.ftc.gov · Accessed 2026-01-19
https://consumer.ftc.gov/
Last code update: 2026-01-19
- Initial audit spec draft generated from HTML extraction (review required).
- Verify formulas match the calculator engine and convert any text-only formulas to LaTeX.
- Confirm sources are authoritative and relevant to the calculator methodology.