Continued Fraction Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

Enter a value.

What Are Continued Fractions?

A continued fraction expresses a real number as a_0+1a_1+1a_2+1a_3+
. Each ai is an integer, and truncating the expansion yields excellent rational approximations. Famous constants like π and e have intriguing patterns in their continued fractions.

Using the Calculator

Provide a decimal number and a maximum number of terms. The algorithm repeatedly takes the integer part, subtracts it, and then inverts the fractional remainder until the desired depth or an exact value is reached. The resulting sequence describes the continued fraction in standard bracket notation.

Insights

Continued fractions reveal number-theoretic properties and often converge faster than simple decimals. They are central in Diophantine approximation, where we seek fractions close to real numbers. Try exploring irrational numbers to see long, non-repeating patterns versus short expansions for rationals.

Example Expansion

Consider 2. The continued fraction for this famous constant is [1; 2, 2, 2, 
]. Truncating after one term yields 1, while after two terms you get 1 + 1/2 = 1.5. After three terms the approximation is 1 + 1/(2 + 1/2) = 1.4. Each additional term brings you closer to 1.41421
, demonstrating how quickly the sequence converges.

Partial Convergents

Each time you stop the expansion, you obtain a rational approximation called a convergent. These convergents alternately overestimate and underestimate the true value, and they are the best possible approximations using denominators of that size. Mathematicians analyze how rapidly the error decreases to understand the quality of the approximation.

A Glimpse of History

Continued fractions were studied extensively by mathematicians such as Euclid, Euler, and Lagrange. They provide insight into Pell’s equation, quadratic irrationals, and even modern algorithms like the Euclidean algorithm for computing greatest common divisors. Today they appear in computer algebra systems and numerical methods where compact rational forms are desirable.

Step-by-Step Algorithm Example

To see the mechanics in action, expand the decimal 3.245 with a depth of four terms. First, take the integer part 3. The remaining fractional part 0.245 is inverted, giving roughly 4.0816. The integer part of that value is 4. Subtract to get 0.0816, invert to 12.25, and continue. The resulting sequence [3; 4, 12, 4] shows how a few simple operations produce a compact rational representation.

Table of Convergents

Convergents illustrate the accuracy of each truncation. The table below shows approximations for π.

TermsConvergent
[3]3
[3; 7]22/7
[3; 7, 15]333/106
[3; 7, 15, 1]355/113

Each successive fraction approximates π more closely, and some—like 355/113—are remarkably accurate for their size.

Where They're Used

Beyond pure mathematics, continued fractions aid in circuit design, control theory, and even in generating musical scales. Their ability to produce best-fit rationals makes them invaluable when hardware or notation limits precision.

How to Read the Convergent Table

When you expand a number with this tool, the table beneath the result lists the convergents—successive rational approximations derived from the continued fraction. The columns labeled h/k show the numerator and denominator of each fraction. The decimal column converts that fraction into a floating‑point approximation, while the error column reports how far the fraction is from the original number. These values are computed using the recurrence formulas hn=anhn-1+hn-2 and kn=ankn-1+kn-2, which build each fraction from the previous two. Watching the error shrink as you move down the table provides an intuitive sense of convergence.

Why Continued Fractions Give the Best Approximations

Suppose you want a fraction with a small denominator that comes very close to a given decimal. Rounding the decimal to a fixed number of places might produce a passable estimate, but a continued fraction often reveals a far better one. Convergents generated from the expansion are guaranteed to be the best rational approximations with denominators up to a certain size. This is formalized in the theory of Diophantine approximation and underpins algorithms for solving Pell’s equation, where we search for integer solutions to x2−Dy2=1. By examining the convergents of D, one can systematically uncover solutions that would be difficult to guess otherwise.

Applications in Computing and Engineering

Digital systems that must represent irrational constants with finite precision frequently turn to continued fractions. For example, implementing a square‑root or trigonometric function in a microcontroller might require a rational approximation with a tiny denominator to keep computation cheap. The convergents from a continued fraction provide exactly that. In signal processing, continued fractions can generate impedances that approximate desired filter characteristics. Even in computer graphics, ratios derived from these expansions help reduce aliasing by approximating slopes with simple fractions, making line‑drawing algorithms more efficient.

Exploring Famous Constants

The calculator is an invitation to explore the hidden structure inside familiar numbers. Enter π or e and examine the repeating or irregular patterns in their coefficients. The golden ratio φ yields the remarkably simple expansion [1; 1, 1, 1, 
], reflecting its self‑similar nature. Square roots of non‑square integers produce periodic continued fractions; for instance, 23 expands to [4; 1, 3, 1, 8, 
] with a repeating block of four terms. Spotting these patterns can lead to deeper insights about the algebraic properties of the numbers themselves.

Step‑by‑Step: From Decimal to Table

  1. Enter the number you want to analyze and choose how many terms to generate. More terms mean a longer continued fraction and tighter approximations.
  2. Press Expand. The bracket notation appears first, summarizing the entire continued fraction.
  3. Review the table. Each row shows a convergent fraction, its decimal form, and the absolute difference from the original number.
  4. Use the Copy Result button to capture the bracket notation and table rows for reference or sharing.
  5. Experiment by changing the depth or entering other numbers. Comparing tables reveals how rapidly different numbers converge.

Working with Rationals and Irrationals

Rational numbers eventually terminate; an input of 5.75, for example, expands to [5; 1, 3]. Once the fractional part reaches zero, the algorithm stops. Irrational numbers never terminate, so the depth field limits how many coefficients are computed. Increasing the depth exposes more of the number’s infinite structure, though the practical usefulness of later terms may diminish as errors from floating‑point arithmetic creep in. For high‑precision work, mathematicians rely on arbitrary‑precision libraries to avoid rounding issues. This calculator aims for educational clarity rather than extreme numeric rigor, but it nonetheless conveys the spirit of continued fraction expansion.

Historical Context and Further Reading

While the concept dates back to ancient mathematics, modern treatment of continued fractions blossomed in the 18th century with the work of Leonhard Euler. Joseph‑Louis Lagrange later proved that quadratic irrationals produce periodic continued fractions, a result that still fascinates number theorists today. Contemporary applications span cryptography—where continued fractions help analyze the security of RSA keys—to chaos theory and dynamical systems. For those eager to dive deeper, classic texts such as Khinchin’s Continued Fractions or Hardy and Wright’s Introduction to the Theory of Numbers provide rigorous yet accessible explorations.

Encouraging Exploration

Numbers are more than strings of digits; they hold patterns and symmetries waiting to be discovered. Continued fractions offer a lens to view these patterns in a fresh light. By experimenting with this calculator—entering random decimals, well‑known constants, or values from puzzles—you build intuition about how numbers behave. The exercise also sharpens mental arithmetic and an appreciation for how infinite processes can yield practical approximations. Whether you are a student encountering number theory for the first time or a hobbyist revisiting it after years away, taking the time to explore continued fractions can be both enlightening and enjoyable.

Related Calculators

Fraction Simplifier Calculator - Reduce Fractions and Perform Basic Operations

Simplify fractions or calculate addition, subtraction, multiplication, and division with this browser-based fraction calculator. Perfect for students, teachers, and anyone working with ratios.

fraction calculator simplify fractions fraction addition math tool

Composite Fiber Volume Fraction Calculator

Determine fiber volume fraction in a composite laminate by entering masses and densities.

composite fiber volume fraction calculator materials science

Fraction-Decimal-Percent Converter

Convert numbers between fraction, decimal, and percent formats with a single tool.

fraction to decimal decimal to percent percent converter