Isqrt (integer square root) of X: Difference between revisions

m
Line 493:
END
</lang>
But for those whom only the quadratic residue algorithm will do, just substitute this form offor the ISQRT() function in the previous example. (The output is identical.) But be warned: there is a bug lurking in the algorithm as presented in the task description. The statement q := q * 4 in the first while loop will overflow the limits of ALGOL-M integer data type (-16,383 to +16,383) for any value of x greater than 4095 and trigger an endless loop.
<lang algol>
% RETURN INTEGER SQUARE ROOT OF N USING QUADRATIC RESIDUE ALGORITHM %
Line 502:
Q := 1;
WHILE Q <= X DO
Q := Q * 4; % WARNING: POSSIBLE OVERFLOW! %
Z := X;
R := 0;
211

edits