141 static IntType add(IntType x, IntType
c)
145 else if(
c <= traits::const_max - m)
146 return add_small(x,
c);
151 static IntType mult(IntType a, IntType x)
155 else if(m <= traits::const_max/a)
156 return mult_small(a, x);
157 else if(traits::is_signed && (m%a < m/a))
158 return mult_schrage(a, x);
168 static IntType mult_add(IntType a, IntType x, IntType
c)
170 if(m <= (traits::const_max-
c)/a)
173 return add(mult(a, x),
c);
176 static IntType invert(IntType x)
177 {
return x == 0 ? 0 : invert_euclidian(x); }
184 static IntType add_small(IntType x, IntType
c)
192 static IntType mult_small(IntType a, IntType x)
197 static IntType mult_schrage(IntType a, IntType value)
199 const IntType
q = m / a;
200 const IntType
r = m % a;
202 value = a*(value%
q) -
r*(value/
q);
209 static IntType invert_euclidian(IntType
c)
220 return (
l2 < 1 ?
l2 + m :
l2);
225 return (
l1 < 1 ?
l1 + m :
l1);