Algorithms and Data Structures © N. Wirth 1985 (Oberon version: August 2004).
§ 1.3 Fast computation of y = x^n
MODULE Power;
PROCEDURE Do*(x: REAL; n: INTEGER): REAL;
VAR y: REAL; i: INTEGER;
BEGIN
ASSERT(n >= 0);
y := 1.0; i := n;
WHILE i > 0 DO (* x0n = xi * y *)
IF ODD(i) THEN y := y*x END;
x := x*x; i := i DIV 2
END
RETURN
y
END Do;
END Power.