// MulRange sets z to the product of all integers // in the range [a, b] inclusively and returns z. // If a > b (empty range), the result is 1. func (z *Int) MulRange(a, b int64) *Int { switch { case a > b: return z.SetInt64(1) // empty range case a <= 0 && b >= 0: return z.SetInt64(0) // range includes 0 } // a <= b && (b < 0 || a > 0) // Can use gmp factorial routine if a = 1 and b >= 1 if a == 1 && b >= 1 { C.mpz_fac_ui(&z.i[0], C.ulong(b)) } else { // Slow z.SetInt64(a) for i := a + 1; i <= b; i++ { C.mpz_mul_si(&z.i[0], &z.i[0], C.long(i)) } } return z }
// MulInt32 sets z to the product x*y and returns z. // // NB This is not part of big.Int func (z *Int) MulInt32(x *Int, y int32) *Int { x.doinit() z.doinit() C.mpz_mul_si(&z.i[0], &x.i[0], C.long(y)) return z }