INNER CODE UNIT · Go

rounding

Consensys/gnark-crypto · ecc/utils.go:285

func rounding(n, d, res *big.Int) {
	var dshift, r, one big.Int
	one.SetUint64(1)
	dshift.Rsh(d, 1)
	r.Mod(n, d)
	res.Div(n, d)
	if r.Cmp(&dshift) == 1 {
		res.Add(res, &one)
	}
}

// roundingSigned rounds n/d to the closest integer and preserves sign.
func roundingSigned(n, d, res *big.Int) {
	if n.Sign() >= 0 {
		rounding(n, d, res)
		return
	}
	var nn big.Int

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…