Continued Fraction Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

What Are Continued Fractions?

A simple continued fraction writes a real number as a0+1a1+1a2+1a3+. Each ai is an integer. Stopping the expansion at any coefficient produces a rational approximation, called a convergent. Familiar constants such as π and e are especially interesting because their coefficient sequences expose structure that a decimal display can hide.

How to use: Using the Continued Fraction Calculator

Enter a decimal number and choose the maximum number of coefficients to generate. This continued fraction calculator takes the integer part, retains the fractional remainder, and inverts that remainder before repeating. It stops when it reaches the selected depth or when the displayed floating-point value has no meaningful fractional remainder. The result is shown in continued-fraction bracket notation, followed by a table of its convergents.

Continued Fraction Insights

Continued fractions turn a decimal into a sequence of integer coefficients and can reveal rational approximations that are much more efficient than simply rounding to a fixed number of decimal places. They are fundamental to Diophantine approximation, the study of fractions close to real numbers. Compare a rational decimal with an irrational-looking decimal: a rational input ends, whereas an irrational input generally continues until the chosen term limit is reached.

Continued Fraction Example Expansion

Consider 2. Its continued fraction is [1; 2, 2, 2, …]. Truncating after one coefficient gives 1; after two coefficients it gives 1 + 1/2 = 1.5; and after three it gives 1 + 1/(2 + 1/2) = 1.4. These convergents lie on opposite sides of 2 and quickly close in on 1.41421…, illustrating why continued fractions are useful for rational approximation.

Continued Fraction Partial Convergents

Every truncation produced by a continued fraction expansion is a rational convergent. For a simple continued fraction, consecutive convergents typically alternate around the original value, and their denominators grow as additional coefficients are used. The calculator’s table makes that progression visible by reporting both the fraction and its absolute error for each completed term.

A Glimpse of Continued Fraction History

Continued fractions connect the ancient Euclidean algorithm with later work by Euler and Lagrange. They illuminate Pell’s equation and the special behavior of quadratic irrationals, whose simple continued fractions are periodic. They also remain practical in computer algebra and numerical work whenever a compact rational form is more useful than a long decimal.

Formula: Continued Fraction Step-by-Step Algorithm Example

To see the continued fraction procedure in action, expand the decimal 3.245 to four terms. Its integer part is 3. Inverting the remaining 0.245 gives about 4.0816, whose integer part is 4. The next fractional remainder is about 0.0816; inverting it gives 12.25, then the next step supplies 4. The coefficient sequence [3; 4, 12, 4] is therefore a compact exact description of this terminating decimal.

Table of Continued Fraction Convergents

The continued fraction convergents below show successive rational approximations for π.

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

As more coefficients of the continued fraction for π are retained, the approximating fractions generally improve. The familiar 355/113 is notably close to π despite its relatively small denominator.

Where Continued Fractions Are Used

Continued fractions are used whenever a real-valued quantity must be represented by a manageable ratio. Applications include rational approximations in numerical computing, impedance and filter calculations, and algorithms that replace an unwieldy slope or ratio with small integers. Their value is not that every convergent is universally optimal for every criterion, but that the expansion supplies a disciplined sequence of particularly useful candidate fractions.

How to Read the Continued Fraction Convergent Table

When this continued fraction calculator expands a number, the table beneath the bracket notation lists its convergents: the fractions made by stopping after each coefficient. The h/k column gives each numerator and denominator. The decimal column evaluates that fraction, and the error column gives its absolute difference from the number entered. The rows are calculated with the recurrences hn=anhn-1+hn-2 and kn=ankn-1+kn-2. Reading downward shows how each new coefficient changes the numerator, denominator, and approximation error.

Introduction: Why Continued Fractions Give Strong Approximations

When a decimal needs a nearby fraction with a modest denominator, a continued fraction gives a more informative route than arbitrary decimal rounding. Its convergents provide a distinguished sequence of rational candidates, often delivering very close approximations with unexpectedly small numerators and denominators. This idea is central to Diophantine approximation and helps explain methods for Pell’s equation, which seeks integer solutions of x2Dy2=1. Examining convergents of D is one systematic way to locate those solutions.

Continued Fractions in Computing and Engineering

In computing and engineering, continued fractions can turn an irrational or high-precision quantity into a ratio suitable for finite hardware or integer arithmetic. A microcontroller implementation of a square-root or trigonometric calculation, for example, may benefit from a close rational approximation with a small denominator. Continued-fraction convergents offer candidates for that job. Related rational forms also arise in signal processing and in representing slopes or timing ratios where simpler integer relationships reduce computational cost.

Exploring Famous Constants with Continued Fractions

This calculator can be used to inspect the coefficient patterns hidden in decimal approximations of well-known constants. Enter a decimal approximation of π or e and examine the resulting coefficients. The golden ratio φ has the simple expansion [1; 1, 1, 1, …], reflecting its self-similar definition. Square roots of non-square integers have periodic simple continued fractions; for example, 23 begins [4; 1, 3, 1, 8, …]. Such patterns connect the output to algebraic properties of the number being expanded.

Step-by-Step: From Decimal to Continued Fraction Table

  1. Enter the decimal value to expand and select the maximum number of continued-fraction terms. More terms can reveal more coefficients and additional convergents.
  2. Press Expand. The calculator displays the coefficient sequence in bracket notation.
  3. Read the convergent table below it. Each row gives the rational fraction formed at that stage, its decimal value, and its absolute error from the entered number.
  4. Use the Copy Result button to copy the displayed continued fraction and its table rows.
  5. Try another decimal or a different depth. Comparing outputs shows the contrast between terminating rational expansions and longer irrational approximations.

Working with Rational and Irrational Continued Fractions

For the decimal value represented by the calculator’s floating-point input, a rational expansion can end when the fractional remainder becomes effectively zero. For example, 5.75 expands to [5; 1, 3]. An irrational number has an infinite continued fraction in exact mathematics, so the Max terms field determines how much of its expansion is displayed here. Increasing that limit exposes more coefficients, but ordinary JavaScript floating-point arithmetic can eventually influence later terms. The tool is best used to explore the expansion and its early convergents rather than as an arbitrary-precision number-theory system.

Continued Fraction Historical Context and Further Reading

The history of continued fractions runs from the Euclidean algorithm through major eighteenth-century work by Leonhard Euler and Joseph-Louis Lagrange. Lagrange’s theorem that quadratic irrationals have periodic simple continued fractions remains a defining result. Modern uses include number theory, cryptographic analysis, dynamical systems, and numerical approximation. Readers seeking a rigorous treatment can consult Khinchin’s Continued Fractions or Hardy and Wright’s Introduction to the Theory of Numbers.

Encouraging Continued Fraction Exploration

Continued fractions invite a different way of looking at a decimal: not as a fixed string of digits, but as a chain of integer choices and rational approximations. Try values from a calculation, decimal approximations of constants, or numbers from a puzzle, then compare the coefficient sequences and errors. This continued fraction calculator is particularly useful for building intuition about why some small fractions are surprisingly accurate and why other decimals require many terms before a close convergent appears.

Continued Fraction Limitations and Assumptions

This continued fraction calculator works with JavaScript floating-point decimal input rather than exact symbolic numbers or arbitrary-precision arithmetic. The reported coefficients and errors therefore describe the entered numeric value and the selected maximum depth. For exact proofs, very deep expansions, or analysis of a value requiring more precision than the input can retain, verify the result with appropriate exact or high-precision mathematics software.

Enter a value.

Arcade Mini-Game: Continued Fraction Calculator Calibration Run

Use this short arcade activity to identify the two inputs that control a continued fraction expansion: the number and the maximum number of terms.

Score: 0 Timer: 30s Best: 0

Start the game, then use your pointer or arrow keys to catch the continued-fraction inputs.