⚠️ Warning: This is a draft ⚠️
This means it might contain formatting issues, incorrect code, conceptual problems, or other severe issues.
If you want to help to improve and eventually enable this page, please fork RosettaGit's repository and open a merge request on GitHub.
COMMENT This routine is used in more than one place, and is essentially a template that can by used for many different types, eg INT, LONG INT... USAGE MODE POWMODSTRUCT = INT, LONG INT, COMPL, FRAC, MODULAS, MATRIX etc PR READ "prelude/pow_mod.a68" PR END COMMENT
PROC pow mod = (POWMODSTRUCT b,in e, mod)POWMODSTRUCT: (
POWMODSTRUCT sq := b, e := in e;
POWMODSTRUCT out:= IF ODD e THEN b ELSE 1 FI;
e:=e OVER 2;
WHILE e /= 0 DO
sq := sq * sq %* mod;
IF ODD e THEN out := out * sq %* mod FI ;
e:=e OVER 2