keisoku

Continued Fraction and Convergent Approximations

Expand a real number into a regular continued fraction and list every fraction approximation (convergent p/q) until a target accuracy or maximum denominator is met. Expressions such as pi or the golden ratio are supported.

Input

x =

Example values (tap to fill in)

pi
e
sqrt(2)
(1+sqrt(5))/2
sqrt(3)
log(10)

Stopping condition

error ≦

Operators: + - * / ^ (power). Functions: sin cos tan exp log (natural log) ln log10 sqrt cbrt abs. Constants: pi (π), e. You may also enter plain integers or decimals.

Result

Best fraction approximation of pi ≒ 3.141592654

355 / 113

= 3.14159292 (Reached target accuracy)

Absolute error

2.668e-7

Denominator q

113

Terms (number of coefficients)

4

Continued fraction notation

[3; 7, 15, 1]

List of fraction approximations (convergents)

Term kCoefficient a_kFraction p/qValueAbsolute error
033 / 130.141592654
1722 / 73.142857140.001264489
215333 / 1063.141509438.322e-5
31355 / 1133.141592922.668e-7

How it works

  • Enter a real value and the tool repeatedly extracts the integer part and the reciprocal to find each coefficient of the regular continued fraction, computing the fraction approximations p/q one by one.
  • Choose the stopping condition as either a target accuracy (absolute error) or a maximum denominator. With accuracy, it stops once the error falls to that value or below; with a denominator limit, it shows the best fraction that does not exceed the given upper bound.
  • The value can also be an expression. Use pi for the circle constant, e for the base of the natural logarithm, and forms such as sqrt(2) or (1+sqrt(5))/2 are evaluated directly. Plain integers and decimals are fine too.
  • The result table lists, for each term, the coefficient a_k, the fraction approximation p/q, its value, and the absolute error from the target. Lower rows have smaller errors, and the row of the chosen best fraction is highlighted.
  • For pi you can watch the accuracy jump as the denominator grows slightly, through 22/7, 333/106, and 355/113. For the golden ratio the numerator and denominator are consecutive Fibonacci numbers.
  • If you enter a rational number, the expansion terminates when it divides evenly, and that fraction is shown as the exact value.