RosettaCodeData/Task/Matrix-exponentiation-operator/ALGOL-68/matrix-exponentiation-operator-2.alg
2023-07-01 13:44:08 -04:00

14 lines
365 B
Text

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
);