Continued fraction
The calculator represents a fraction as continued fraction
This content is licensed under Creative Commons Attribution/Share-Alike License 3.0 (Unported). That means you may freely redistribute or modify this content under the same license conditions and must attribute the original author by placing a hyperlink from your site to this work https://planetcalc.com/8456/. Also, please do not modify any references to the original work (if any) contained in this content.
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.
The calculator below converts the continued fraction coefficients back to the rational number.
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.
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;
Comments