4 #include "base/cl_sysdep.h"
7 #include "cln/integer.h"
12 #include "integer/cl_I.h"
16 const cl_I expt_pos (const cl_I& x, const cl_I& y)
19 // a:=x, b:=y, c:=1. [a^b*c bleibt invariant, = x^y.]
21 // falls b ungerade, setze c:=a*c,
22 // setze b:=floor(b/2),
24 // Wenn b=1, setze c:=a*c.
28 // Solange b gerade, setze a:=a*a, b:=b/2. [a^b bleibt invariant, = x^y.]
30 // Solange b:=floor(b/2) >0 ist,
31 // setze a:=a*a, und falls b ungerade, setze c:=a*c.
40 b = b >> 1; // b := (floor b 2)
47 while (!oddp(b)) { a = square(a); b = b >> 1; }
52 if (oddp(b)) { c = a * c; }
57 // Bit complexity (x of length N): O(M(N*y)).