Calculating the simple continued fraction of a quadratic irrational
This program finds the continued fraction expansion of a
quadratic irrational (u + t√d)/v, where d,t,u,v are integers, d >1 and nonsquare, t nonzero, v > 0.
We use the continued fraction algorithm as described in K. Rosen,
Elementary Number theory and its applications, 379-381 and Knuth's
The art of computer programming, Vol. 2, p. 359.
The first reduced complete quotient is located and this leads to the period.
(Also see MP313 lecture notes.)
E=1 prints the partial quotients, convergents and complete quotients, whereas E=0 prints only the partial quotients.
The period is printed in bold font.
Last modified 12th December 2017
Return to main page