1 // operator<< on cl_MI.
7 #include "cln/modinteger.h"
12 #include "cln/integer.h"
16 const cl_MI operator<< (const cl_MI& x, sintL y) // assume 0 <= y < 2^31
20 if (y == 1) // frequent case
22 var const cl_modint_ring& R = x.ring();
24 // Algorithm 1: divide (x.rep << y) by m.
25 // asymptotical cost: O(y * log m).
26 // Algorithm 2: x * expt(2 mod m,y) using modular integer operations.
27 // asymptotical cost: O(log y * (log m)^2).
28 // Use algorithm 1 for small y, algorithm 2 for large y.
29 if ((R->bits < 0) || (y <= 2*R->bits))
30 return cl_MI(R, R->reduce_modulo(x.rep << y));
32 return x * expt_pos(R->canonhom(2), (cl_I)(long)y);