Continued Fraction Calculator and Rational Approximation Tool

Convert an exact fraction or finite decimal into a simple continued fraction, inspect its convergents, and find the closest fraction within a denominator limit. Your input stays in your browser.

Enter a rational value

Examples: 43/30, -2.75, or 1.25e-4. Up to 300 significant digits and an exponent from −1,000 to 1,000.

Expansion and approximation

Your result will appear here.

With 355/113, select Calculate to see [3; 7, 16] and all three convergents.

Advertisement

What is a simple continued fraction?

A simple continued fraction writes a number using an integer part and reciprocals of positive integers. The compact notation [a₀; a₁, a₂, …] means:

a₀ + 1/(a₁ + 1/(a₂ + 1/(…)))

For a rational input, repeated Euclidean division eventually reaches remainder zero, so the expansion is finite. This tool uses the canonical finite form: the final term is greater than 1 unless the value is an integer.

For negative values, a0 is the mathematical floor. For example, −22/7 = [−4; 1, 6], with every term after the first remaining positive.

How the calculation works

  1. Parse the text as an exact numerator and positive denominator, then reduce by their greatest common divisor.
  2. Take a0 = floor(n/d) and keep the non-negative remainder.
  3. Replace n/d with d/r and repeat until the remainder is zero.
  4. Build convergents from the recurrence at right.
  5. For the denominator limit, check the last eligible convergent and the boundary intermediate fraction, then compare their exact errors.

Convergent recurrence

p₋₂ = 0, p₋₁ = 1
q₋₂ = 1, q₋₁ = 0

pₖ = aₖpₖ₋₁ + pₖ₋₂
qₖ = aₖqₖ₋₁ + qₖ₋₂

The kth convergent is pₖ/qₖ. All calculations use exact BigInt integer arithmetic rather than binary floating point.

Worked example: 355/113

Euclidean quotients

355 = 3 × 113 + 16
113 = 7 × 16 + 1
16 = 16 × 1 + 0

The quotients are 3, 7, and 16, giving [3; 7, 16].

Convergents

3/1, 22/7, 355/113

Each added term refines the fraction. With a maximum denominator of 100, the closest allowed result is 311/99; intermediate fractions can beat the last full convergent when the limit falls between convergent denominators.

Input meaning and limits

InputExact value used
43/30The entered numerator divided by the entered nonzero denominator, reduced exactly.
0.125The finite decimal 125/1000 = 1/8, not an approximate binary floating-point value.
1.25e-4The exact decimal 0.000125 = 1/8000.
Decimal digits of π or √2The finite digits entered. The tool does not infer a named irrational constant.

Limits: 300 significant digits; scientific exponent from −1,000 to 1,000; maximum denominator from 1 to 1,000,000,000,000; and at most 200 displayed terms. If an exact expansion is longer than the display limit, the approximation still uses the complete input value.

Continued fraction FAQ

What is a convergent?

A convergent is the exact fraction obtained by stopping at a term of the continued fraction. Its numerator and denominator come from the recurrence above.

Is the last convergent always the best fraction under my denominator limit?

Not always. When a limit lies between two convergent denominators, an intermediate (semiconvergent) fraction may be closer. The bounded-denominator result checks the relevant boundary candidate as well as the last eligible convergent.

Can this calculator expand π or √2 exactly?

No. Irrational numbers have infinite non-repeating continued fractions and cannot be supplied exactly as a finite decimal. Example buttons use finite decimal approximations and clearly treat those digits as the exact input.

Why can the same rational number have two finite forms?

If the last term is greater than 1, it can be replaced by one less followed by 1. For example, [3; 7, 16] = [3; 7, 15, 1]. This tool returns the shorter canonical form ending above 1.

How are negative numbers handled?

The first term is the floor of the value, not truncation toward zero. Later terms are positive, so the output remains a standard simple continued fraction.

Are decimal inputs affected by floating-point rounding?

No. The decimal text is converted directly into a ratio of integers and simplified. Approximate decimal previews are for readability; fractions and error ratios are exact.

Are my inputs private?

Yes. Parsing, continued-fraction expansion, and rational comparison happen locally in your browser. Inputs are not uploaded, stored, or added to the page URL.

Explore more tools