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; } }
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); }