예제 #1
0
파일: random.hpp 프로젝트: rtsuk/fmsync
 static IntType mult(IntType a, IntType x)
 {
   if(a == 1)
     return x;
   else if(m <= traits::const_max/a)      // i.e. a*m <= max
     return mult_small(a, x);
   else if(traits::is_signed && (m%a < m/a))
     return mult_schrage(a, x);
   else {
     // difficult
     assert(!"const_mod::mult with a too large");
     return 0;
   }
 }
예제 #2
0
 static IntType mult(IntType a, IntType x)
 {
     if(((unsigned_m() - 1) & unsigned_m()) == 0)
         return unsigned_type(a) * unsigned_type(x) & (unsigned_m() - 1);
     else if(a == 0)
         return 0;
     else if(a == 1)
         return x;
     else if(m <= traits::const_max/a)      // i.e. a*m <= max
         return mult_small(a, x);
     else if(traits::is_signed && (m%a < m/a))
         return mult_schrage(a, x);
     else
         return mult_general(a, x);
 }