We consider the following:

where all the numerators {a1,a2,a3,…} are given and they can be different from ones. We construct a continued fraction of x.
(1) Find b0 in x=b0+a1/x1 where b0 is the largest integer that is less than or equal to x.
(2) Calculate the residual x-b0 and set it to a1/x1.
(3) Find b1 in x1=b1+a2/x2 where b1 is the largest integer that is less than or equal to x1.
(4) Calculate the residual x1-b1 and set it to a2/x2 if it is not zero.
(5) If it is zero, stop there. Otherwise we repeat this for many times.
If we allow signs between terms to be different from positive ones, the algorithm is modified as follows:
(1) Find b0 in x=b0+a1/x1 where b0 is the largest integer that is less than or equal to x if the first sign is positive. Find b0 in x=b0-a1/x1 where b0 is the smallest integer that is greater than or equal to x otherwise.
(2) Calculate the residual |x-b0| and set it to a1/x1.
(3) Find b1 in x1=b1+1/x2 where b1 is the largest integer that is less than or equal to x1 if the second sign is positive. Find b1 in x1=b1-1/x2 where b1 is the smallest integer that is greater than or equal to x1 otherwise.
(4) Calculate the residual |x1-b1| and set it to a2/x2 if it is not zero.
(5) If it is zero, stop there. Otherwise we repeat this for many times.