WHILE r # 0
DO
rinv: REAL ← Inverse[r];
fnew: NAT ← FloorN[rinv];
pnew: LONG CARDINAL ← Basics.LongMult[fnew, p] + pp;
qnew: LONG CARDINAL ← Basics.LongMult[fnew, q] + qq;
IF pnew > NAT.LAST OR qnew > CARDINAL.LAST THEN EXIT;
pp ← p;
qq ← q;
p ← pnew;
q ← qnew;
r ← rinv - fnew;
ENDLOOP;