// math.Round was not added until Go 1.10, can be removed when support for Go
// 1.9 is dropped.
438098
func Round(x float64) float64 {
	t := math.Trunc(x)
	if math.Abs(x-t) >= 0.5 {
		return t + math.Copysign(1, x)
	}
	return t
}
772508
func float64ToInt(input float64) (output int) {
	r, _ := Round(input, 0)
	return int(r)
}
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)
}
1310599
func (d *MyDecimal) String() string {
	tmp := *d
	tmp.Round(&tmp, int(tmp.resultFrac))
	return string(tmp.ToString())
}
994894
func sqrt3(z *decimal.Big, ctx decimal.Context) *decimal.Big {
	if ctx.Precision <= constPrec {
		return ctx.Set(z, _Sqrt3)
	}
	// TODO(eric): get rid of this allocation.
	return ctx.Set(z, Sqrt(decimal.WithContext(ctx), three))
}
609275
func (g *Geometry) Simplify(tolerance float64) (*Geometry, error) {
	return g.simplify("simplify", cGEOSSimplify, tolerance)
}
369129
func (m mathUtil) RoundUp(value, roundTo float64) float64 {
	if roundTo < 0.000000000000001 {
		return value
	}
	d1 := math.Ceil(value / roundTo)
	return d1 * roundTo
}
312950
func (z *Dec) Round(x *Dec, s Scale, r Rounder) *Dec {
	return z.QuoRound(x, NewDec(1, 0), s, r)
}
773846
func (m mathUtil) Normalize(values ...float64) []float64 {
	var total float64
	for _, v := range values {
		total += v
	}
	output := make([]float64, len(values))
	for x, v := range values {
		output[x] = m.RoundDown(v/total, 0.0001)
	}
	return output
}
29450
func round(d time.Duration, step time.Duration, roundCloser bool) time.Duration {

	if roundCloser {
		return time.Duration(float64(d)/float64(step) + 0.5)
	}

	return time.Duration(float64(d) / float64(step))
}
746002
func round(x float64) int64 {
	if _, frac := math.Modf(x); frac >= 0.5 {
		return int64(math.Ceil(x))
	}
	return int64(math.Floor(x))
}
119627
func (u *Ugen) Round(val Input) Input {
	return binOpRound(u.Rate, u, val, u.NumOutputs)
}
848294
func (ns *Namespace) Round(x interface{}) (float64, error) {
	xf, err := cast.ToFloat64E(x)
	if err != nil {
		return 0, errors.New("Round operator can't be used with non-float value")
	}

	return _round(xf), nil
}
811516
func FormatGPS(l float64) string {
	padding := ""
	degrees := math.Floor(math.Abs(l))
	fraction := (math.Abs(l) - degrees) * 60
	if fraction < 10 {
		padding = "0"
	}
	return fmt.Sprintf("%d%s%.4f", int(degrees), padding, fraction)
}
312935
func Round(g Geometry, factor ...int) Geometry {
	if g == nil {
		return nil
	}

	f := float64(DefaultRoundingFactor)
	if len(factor) > 0 {
		f = float64(factor[0])
	}

	switch g := g.(type) {
	case Point:
		return Point{
			math.Round(g[0]*f) / f,
			math.Round(g[1]*f) / f,
		}
	case MultiPoint:
		if g == nil {
			return nil
		}
		roundPoints([]Point(g), f)
		return g
	case LineString:
		if g == nil {
			return nil
		}
		roundPoints([]Point(g), f)
		return g
	case MultiLineString:
		if g == nil {
			return nil
		}
		for _, ls := range g {
			roundPoints([]Point(ls), f)
		}
		return g
	case Ring:
		if g == nil {
			return nil
		}
		roundPoints([]Point(g), f)
		return g
	case Polygon:
		if g == nil {
			return nil
		}
		for _, r := range g {
			roundPoints([]Point(r), f)
		}
		return g
	case MultiPolygon:
		if g == nil {
			return nil
		}
		for _, p := range g {
			for _, r := range p {
				roundPoints([]Point(r), f)
			}
		}
		return g
	case Collection:
		if g == nil {
			return nil
		}

		for i := range g {
			g[i] = Round(g[i], int(f))
		}
		return g
	case Bound:
		return Bound{
			Min: Point{
				math.Round(g.Min[0]*f) / f,
				math.Round(g.Min[1]*f) / f,
			},
			Max: Point{
				math.Round(g.Max[0]*f) / f,
				math.Round(g.Max[1]*f) / f,
			},
		}
	}

	panic(fmt.Sprintf("geometry type not supported: %T", g))
}
761207
func roundTime(t gotime.Time, fsp int) gotime.Time {
	d := gotime.Duration(math.Pow10(9 - fsp))
	return t.Round(d)
}
1291852
func calcDigest(inputs map[string][]byte) string {
	keys := make([]string, 0, len(inputs))
	for k := range inputs {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	h := sha1.New()
	for _, k := range keys {
		v := inputs[k]
		fmt.Fprintf(h, "%s\n%d\n", k, len(v))
		h.Write(v)
	}
	blob := h.Sum(nil)
	return hex.EncodeToString(blob[:])
}