Continued fraction

The calculator represents a fraction as continued fraction

This page exists due to the efforts of the following people:

Anton

Timur

Timur

Created: 2019-11-04 20:40:06, Last updated: 2021-02-14 09:05:37

The calculator below represents a given rational number as a finite continued fraction. It also shows the continued fraction coefficients (the first coefficient is the integer part). Read more on continued fractions just below the calculator.

PLANETCALC, Rational number to continued fraction

Rational number to continued fraction

Continued fraction
 
Coefficients
 

The calculator below converts the continued fraction coefficients back to the rational number.

PLANETCALC, Continued fraction to rational number

Continued fraction to rational number

Rational number
 
Continued fraction
 

Continued (recurring) fraction

Continued or recurring fraction is a number representation kind as a sum of the number integer part and the fractional part. The fractional part numerator is always one, the denominator is the sum of the integer part and the fractional part. The fractional part denominator may again contain the sum of integer and fractional part and so on.
a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{ \ddots + \cfrac{1}{a_n} }}}
a0,a1,a2...an is the continued fraction coefficients.
We use the following algorithm to calculate continued fraction coefficients:

// n - the fraction numerator
// d - the fraction denominator

loop while d ≠ 0
        r ⟵  n mod d;
        output ⟵ (n-r)/d;
        n ⟵ d;
        d ⟵ r;
 end loop  

The reverse transformation algorithm:

// f[] - the continued fraction coefficient array with indexes 0...k-1
// k - number of the coefficients
n ⟵ f[k-1];
d ⟵ 1;
loop while k greater than 1 
        r ⟵  d;
        d ⟵ n;
        k ⟵ k-1;
        n ⟵ f[k-1]*n+r;
end loop  
output ⟵ n/d;
URL copied to clipboard
PLANETCALC, Continued fraction

Comments