RosettaCodeData/Task/Matrix-exponentiation-operator/ALGOL-68/matrix-exponentiation-operator-2.alg

15 lines
365 B
Text
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
OP ** = (MAT base, INT exponent)MAT: (
BITS binary exponent:=BIN exponent ;
MAT out := IF bits width ELEM binary exponent THEN base ELSE IDENTITY UPB base FI;
MAT sq:=base;
WHILE
binary exponent := binary exponent SHR 1;
binary exponent /= BIN 0
DO
sq := sq * sq;
IF bits width ELEM binary exponent THEN out := out * sq FI
OD;
out
);