Continued Fraction Converter

Express any real number as a continued fraction expansion

Ad placeholder (leaderboard)

A continued fraction writes a number as an integer plus a reciprocal of an integer plus a reciprocal, nesting indefinitely. It produces the cleanest possible ladder of rational approximations — the convergents — which is why it underlies calendar design, gear ratios, and the best rational approximations of constants like pi.

How it works

The expansion is built by a simple repeat: take the floor, subtract it, reciprocate the remaining fractional part, and go again.

pi = 3.14159265...
  a0 = 3   remainder 0.14159...  ->  1/0.14159 = 7.0625...
  a1 = 7   remainder 0.0625...   ->  1/0.0625  = 15.99...
  a2 = 15  ...
  pi = [3; 7, 15, 1, ...]

Each truncation [a0; a1, ..., ak] is a convergent p_k / q_k, computed with the recurrence p_k = a_k * p_(k-1) + p_(k-2) and q_k = a_k * q_(k-1) + q_(k-2). The convergents are the best rational approximations for their denominator size and alternate just above and just below the true value, tightening at every step.

Tips and notes

The output uses the standard bracket notation with a semicolon after the integer part, for example [3; 7, 15, 1]. Each listed convergent shows its decimal value and absolute error so you can pick the trade-off you want between simplicity and accuracy. Because the input is read as a floating-point decimal, very long expansions eventually reflect rounding rather than the true number, so keep the term count modest unless you entered a high-precision value.

Ad placeholder (rectangle)