A large commit.
[pdp8.git] / sw / src / pascal / POWER.PS
1 FUNCTION POWER(X: REAL; Y: INTEGER): REAL ; (*Y >= 0*)
2 VAR W,Z: REAL; I: INTEGER;
3 BEGIN W := X; Z := 1; I := Y;
4 WHILE I > 0 DO
5 BEGIN (*Z*(W**I) = X ** Y*)
6 IF ODD(I) THEN Z := Z*W;
7 I := I DIV 2;
8 W := SQR(W)
9 END;
10 (*Z = X**Y*)
11 POWER := Z
12 END;