// Mod returns the remainder of x / d
355008
func (x Pol) Mod(d Pol) Pol {
	_, r := x.DivMod(d)
	return r
}
718973
func sqrtMod(x *big.Int, p *big.Int) (z *big.Int) {
	/* assert that p % 4 == 3 */
	if new(big.Int).Mod(p, big.NewInt(4)).Cmp(big.NewInt(3)) != 0 {
		panic("p is not equal to 3 mod 4!")
	}

	/* z = sqrt(x) % p = x^((p+1)/4) % p */

	/* e = (p+1)/4 */
	e := new(big.Int).Add(p, big.NewInt(1))
	e = e.Rsh(e, 2)

	z = expMod(x, e, p)
	return z
}
57166
func ModGet(xu *xgbutil.XUtil, keycode xproto.Keycode) uint16 {
	modMap := ModMapGet(xu)

	var i byte
	for i = 0; int(i) < len(modMap.Keycodes); i++ {
		if modMap.Keycodes[i] == keycode {
			return Modifiers[i/modMap.KeycodesPerModifier]
		}
	}
	return 0
}
157171
func randomBytesMod(length int, mod byte) (b []byte) {
	if length == 0 {
		return nil
	}
	if mod == 0 {
		panic("captcha: bad mod argument for randomBytesMod")
	}
	maxrb := 255 - byte(256%int(mod))
	b = make([]byte, length)
	i := 0
	for {
		r := randomBytes(length + (length / 4))
		for _, c := range r {
			if c > maxrb {
				// Skip this number to avoid modulo bias.
				continue
			}
			b[i] = c % mod
			i++
			if i == length {
				return
			}
		}
	}

}
1038259
func ModMapSet(xu *xgbutil.XUtil, modMapReply *xproto.GetModifierMappingReply) {
	xu.Modmap = &xgbutil.ModifierMapping{modMapReply}
}
838453
func (d *Context) XmoveTop(fromCtx *Context, count int) {
	C._duk_xmove_top(d.duk_context, fromCtx.duk_context, C.duk_idx_t(count))
}
63350
func (x Pol) Expand() string {
	if x == 0 {
		return "0"
	}

	s := ""
	for i := x.Deg(); i > 1; i-- {
		if x&(1<<uint(i)) > 0 {
			s += fmt.Sprintf("+x^%d", i)
		}
	}

	if x&2 > 0 {
		s += "+x"
	}

	if x&1 > 0 {
		s += "+1"
	}

	return s[1:]
}
570643
func crcHashMod(key string, cardinality int) int {
	if cardinality <= 0 {
		return -1
	}
	keyCrc := crc32.Checksum([]byte(key), crc32.IEEETable)
	return int(keyCrc % uint32(cardinality))
}
305914
func Module(mod ModuleFunc) func(*Runner) error {
	return func(r *Runner) error {
		switch mod := mod.(type) {
		case ModuleExec:
			if mod == nil {
				mod = DefaultExec
			}
			r.Exec = mod
		case ModuleOpen:
			if mod == nil {
				mod = DefaultOpen
			}
			r.Open = mod
		default:
			return fmt.Errorf("unknown module type: %T", mod)
		}
		return nil
	}
}
678418
func clamp(x, x0, x1 float64) float64 {
	if x < x0 {
		return x0
	}
	if x > x1 {
		return x1
	}
	return x
}
25370
func (x Pol) MulMod(f, g Pol) Pol {
	if x == 0 || f == 0 {
		return 0
	}

	var res Pol
	for i := 0; i <= f.Deg(); i++ {
		if (f & (1 << uint(i))) > 0 {
			a := x
			for j := 0; j < i; j++ {
				a = a.Mul(2).Mod(g)
			}
			res = res.Add(a).Mod(g)
		}
	}

	return res
}
267929
func ComputeMod(sc *variable.StatementContext, a, b Datum) (d Datum, err error) {
	switch a.Kind() {
	case KindInt64:
		x := a.GetInt64()
		switch b.Kind() {
		case KindInt64:
			y := b.GetInt64()
			if y == 0 {
				return d, nil
			}
			d.SetInt64(x % y)
			return d, nil
		case KindUint64:
			y := b.GetUint64()
			if y == 0 {
				return d, nil
			} else if x < 0 {
				d.SetInt64(-int64(uint64(-x) % y))
				// first is int64, return int64.
				return d, nil
			}
			d.SetInt64(int64(uint64(x) % y))
			return d, nil
		}
	case KindUint64:
		x := a.GetUint64()
		switch b.Kind() {
		case KindInt64:
			y := b.GetInt64()
			if y == 0 {
				return d, nil
			} else if y < 0 {
				// first is uint64, return uint64.
				d.SetUint64(uint64(x % uint64(-y)))
				return d, nil
			}
			d.SetUint64(x % uint64(y))
			return d, nil
		case KindUint64:
			y := b.GetUint64()
			if y == 0 {
				return d, nil
			}
			d.SetUint64(x % y)
			return d, nil
		}
	case KindFloat64:
		x := a.GetFloat64()
		switch b.Kind() {
		case KindFloat64:
			y := b.GetFloat64()
			if y == 0 {
				return d, nil
			}
			d.SetFloat64(math.Mod(x, y))
			return d, nil
		}
	case KindMysqlDecimal:
		x := a.GetMysqlDecimal()
		switch b.Kind() {
		case KindMysqlDecimal:
			y := b.GetMysqlDecimal()
			to := new(MyDecimal)
			err = DecimalMod(x, y, to)
			if err != ErrDivByZero {
				d.SetMysqlDecimal(to)
			} else {
				// div by zero returns nil without error.
				err = nil
			}
			return d, err
		}
	}
	_, err = InvOp2(a.GetValue(), b.GetValue(), opcode.Mod)
	return d, errors.Trace(err)
}
980218
func Modadd(a, b, m *FP256BN.BIG) *FP256BN.BIG {
	c := a.Plus(b)
	c.Mod(m)
	return c
}
978991
func (x VarInt) Bytes() []byte {
	b := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // 9.14 bytes are needed
	ux := uint64(x) << 1
	if x < 0 {
		ux = ^ux
	}
	pos := 0
	for {
		b[pos] = byte((ux & 0x7F) | 0x80)
		pos++
		if ux >= 128 {
			ux >>= 7
		} else {
			break
		}
	}
	b[pos-1] &= 0x7F
	return b[0:pos]
}
445310
func (fif *FileInfoFast) ModTime() time.Time {
	return time.Unix(0, fif.ei.Mtime)
}
362302
func subMod(x *big.Int, y *big.Int, p *big.Int) (z *big.Int) {
	z = new(big.Int).Sub(x, y)
	z.Mod(z, p)
	return z
}
935340
func (as ArraySpec) Moddif(y, mod Input) Input {
	return as.proc(func(i Input) Input {
		return i.Moddif(y, mod)
	})
}