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