Continued-fraction algorithm (source code)

= Continued-fraction algorithm

Starting from $x_0=x>0$, define
$$
a_n=\lfloor x_n\rfloor,
\qquad
x_{n+1}=\frac1{x_n-a_n}
$$
whenever $x_n$ is not an integer. This produces $x=[a_0;a_1,a_2,\ldots]$.