// round rounds a float64
428987
func round(a float64) float64 {
	if a < 0 {
		return math.Ceil(a - 0.5)
	}
	return math.Floor(a + 0.5)
}
1037654
func (p *Partial) Float64() (f float64, err error) {
	err = p.Unmarshal(&f)
	return
}
453304
func roundString(b []byte, mode RoundingMode, pos bool, prec int) []byte {
	if prec >= len(b) {
		return append(b, bytes.Repeat(zero, prec-len(b))...)
	}

	// Trim zeros until prec. This is useful when we can round exactly by simply
	// chopping zeros off the end of the number.
	if allZeros(b[prec:]) {
		return b[:prec]
	}

	b = b[:prec+1]
	i := prec - 1

	// Blindly increment b[i] and handle possible carries later.
	switch mode {
	case AwayFromZero:
		b[i]++
	case ToZero:
		// OK
	case ToPositiveInf:
		if pos {
			b[i]++
		}
	case ToNegativeInf:
		if !pos {
			b[i]++
		}
	case ToNearestEven:
		if b[i+1] > '5' || b[i+1] == '5' && b[i]%2 != 0 {
			b[i]++
		}
	case ToNearestAway:
		if b[i+1] >= '5' {
			b[i]++
		}
	}

	if b[i] != '9'+1 {
		return b[:prec]
	}

	// We had to carry.
	b[i] = '0'

	for i--; i >= 0; i-- {
		if b[i] != '9' {
			b[i]++
			break
		}
		b[i] = '0'
	}

	// Carried all the way over to the first column, so slide the buffer down
	// and instead of reallocating.
	if b[0] == '0' {
		copy(b[1:], b)
		b[0] = '1'
		// We might end up with an extra digit of precision. E.g., given the
		// decimal 9.9 with a requested precision of 1, we'd convert 99 -> 10.
		// Let the calling code handle that case.
		prec++
	}
	return b[:prec]
}
1171807
func (c Context) Round(z *Big) *Big {
	if debug {
		z.validate()
	}
	if z.invalidContext(c) {
		return z
	}

	n := precision(c)
	if n == UnlimitedPrecision || z.isSpecial() {
		return z
	}

	zp := z.Precision()
	if zp <= n {
		return c.fix(z)
	}

	shift := zp - n
	if shift > c.maxScale() {
		return z.xflow(c.minScale(), false, true)
	}
	z.exp += shift

	z.Context.Conditions |= Rounded

	c.shiftr(z, uint64(shift))
	return c.fix(z)
}
1144672
func (fs *FlagSet) Float64(names []string, value float64, usage string) *float64 {
	p := new(float64)
	fs.Float64Var(p, names, value, usage)
	return p
}
849055
func Float(v float64) *float64 {
	ptr := new(float64)
	*ptr = v
	return ptr
}
53726
func (a *Array) Float64(f float64) *Array {
	a.buf = enc.AppendFloat64(enc.AppendArrayDelim(a.buf), f)
	return a
}
116635
func round(d, r time.Duration) time.Duration {
	if r <= 0 {
		return d
	}
	neg := d < 0
	if neg {
		d = -d
	}
	if m := d % r; m+m < r {
		d = d - m
	} else {
		d = d + r - m
	}
	if neg {
		return -d
	}
	return d
}
254245
func roundDuration(in int64) int64 {
	abs := in
	if abs < 0 {
		abs = -abs
	}
	if abs <= 10 { // 10s -> don't round
		return in
	} else if abs <= 60 { // 1min -> round to 10s
		return round(in, 10)
	} else if abs <= 600 { // 10min -> round to 1min
		return round(in, 60)
	} else if abs <= 3600 { // 1h -> round to 10min
		return round(in, 600)
	} else if abs <= 3600*24 { // 24h -> round to 1h
		return round(in, 3600)
	} else if abs <= 3600*24*7 { // 7d -> round to 1d
		return round(in, 3600*24)
	} else if abs <= 3600*24*30 { // 30d -> round to 7d
		return round(in, 3600*24*7)
	}
	// default to rounding to months
	return round(in, 3600*24*30)
}
1072884
func (l *Locking) Float64() (v float64) {
	l.Lock()
	v = l.R.Float64()
	l.Unlock()
	return
}
862614
func (a *decimal) Round(nd int) {
	if nd < 0 || nd >= a.nd {
		return
	}
	if shouldRoundUp(a, nd) {
		a.RoundUp(nd)
	} else {
		a.RoundDown(nd)
	}
}
745337
func roundAngle(val s1.Angle) int32 {
	if val < 0 {
		return int32(val - 0.5)
	}
	return int32(val + 0.5)
}
1284905
func Roundf(a, b float32) float32 {
	if b == 0 {
		return 0
	}
	var m, v float32

	for {
		if b*m <= a {
			if b*(m+1) > a {
				if math.Abs(float64(a-b*m)) < math.Abs(float64(a-b*(m+1))) {
					v = b * m
				} else {
					v = b * (m + 1)
				}
				break
			}
			m++
			continue
		}
		m--
		if b*m <= a {
			if math.Abs(float64(a-b*m)) < math.Abs(float64(a-b*(m+1))) {
				v = b * m
			} else {
				v = b * (m + 1)
			}
			break
		}
	}
	return v
}
1009327
func (c Context) RoundToInt(z *Big) *Big {
	if z.isSpecial() || z.exp >= 0 {
		return z
	}
	c.Precision = z.Precision()
	return c.Quantize(z, 0)
}
247014
func Round(f float64, n int) float64 {
	pow10n := math.Pow10(n)
	return math.Trunc((f+0.5/pow10n)*pow10n) / pow10n
}
746002
func round(x float64) int64 {
	if _, frac := math.Modf(x); frac >= 0.5 {
		return int64(math.Ceil(x))
	}
	return int64(math.Floor(x))
}
626016
func (a *decimal) RoundedInteger() uint64 {
	if a.dp > 20 {
		return 0xFFFFFFFFFFFFFFFF
	}
	var i int
	n := uint64(0)
	for i = 0; i < a.dp && i < a.nd; i++ {
		n = n*10 + uint64(a.d[i]-'0')
	}
	for ; i < a.dp; i++ {
		n *= 10
	}
	if shouldRoundUp(a, a.dp) {
		n++
	}
	return n
}