# Calculate a Continued Fraction

Calculator for continued fractions up to a certain number of calculation steps. A continued fraction has the form _{1}+b_{1}/(a_{2}+b_{2}/(...))_{i} and b_{i} can be represented as formulas. n must be a positive integer, it is started with the value of n and then calculated to 1. As running variable in the formulas, i is used. The basic arithmetic operations + - * / are allowed, as well as the power function pow(), like pow(2#i) for 2^{i}. Further allowed functions are sin(), cos(), tan(), asin(), acos(), atan() and log() for the natural logarithm. Also, the constants e and pi can be used.

The calculation is done backwards:

k_{n} = a_{n} + b_{n}

k_{n-1} = a_{n-1} + b_{n-1} / k_{n}

k_{n-2} = a_{n-2} + b_{n-2} / k_{n-1}

...

k_{1} = a_{1} + b_{1} / k_{2}

Examples:

- 1+1/(1+1/(1+1/(...))), where a=1 and b=1, is the continued fraction expansion of the golden ratio.
- a=6 and b=pow(2*i-1#2) approaches the value of π+3. After 100 steps, the result is 6.1415923985336, the exact value with 13 decimal places is 6.1415926535898. This is reached after about 20000 steps.