// Sqrt performs √a̅ elementwise. a̅ will be clobbered
543000
func Sqrt(a []float64) {
	for i, v := range a {
		a[i] = math.Sqrt(v)
	}
}
119627
func (u *Ugen) Round(val Input) Input {
	return binOpRound(u.Rate, u, val, u.NumOutputs)
}
187712
func clamp(x float64) uint8 {
	v := int64(x + 0.5)
	if v > 255 {
		return 255
	}
	if v > 0 {
		return uint8(v)
	}
	return 0
}
996188
func (sf *ScalarFunction) EvalDecimal(ctx sessionctx.Context, row chunk.Row) (*types.MyDecimal, bool, error) {
	return sf.Function.evalDecimal(row)
}
249464
func (quat *T) Norm() float64 {
	return quat[0]*quat[0] + quat[1]*quat[1] + quat[2]*quat[2] + quat[3]*quat[3]
}
88895
func DistanceFromSegmentSquared(a, b, point orb.Point) float64 {
	x := a[0]
	y := a[1]
	dx := b[0] - x
	dy := b[1] - y

	if dx != 0 || dy != 0 {
		t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy)

		if t > 1 {
			x = b[0]
			y = b[1]
		} else if t > 0 {
			x += dx * t
			y += dy * t
		}
	}

	dx = point[0] - x
	dy = point[1] - y

	return dx*dx + dy*dy
}
641895
func gauss(n int, s, a, l, u float64) []float64 {
	// Make output of gauss deterministic by seeding with a fixed value.
	rand.Seed(12345)
	points := make([]float64, n)
	for i := 0; i < len(points); i++ {
		x := rand.NormFloat64()*s + a
		if x < l {
			x = l
		} else if x > u {
			x = u
		}
		points[i] = x
	}
	return points
}
961326
func FeSquare(h, f *FieldElement) {
	h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 := feSquare(f)
	FeCombine(h, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9)
}
443419
func distanceFromSegmentSquared(a, b, point []float64) float64 {
	x := a[0]
	y := a[1]
	dx := b[0] - x
	dy := b[1] - y

	if dx != 0 || dy != 0 {
		t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy)

		if t > 1 {
			x = b[0]
			y = b[1]
		} else if t > 0 {
			x += dx * t
			y += dy * t
		}
	}

	dx = point[0] - x
	dy = point[1] - y

	return dx*dx + dy*dy
}
73899
func (m *Matrix) Round() *Matrix {
	rows, cols := m.Size()
	for row := 0; row < rows; row++ {
		for col := 0; col < cols; col++ {
			m.Set(row, col, roundToEpsilon(m.Get(row, col), m.epsilon))
		}
	}
	return m
}
1099599
func AudioLevel(samples []int32) float64 {
	// Compute sum of square values
	var sum float64
	for _, s := range samples {
		sum += math.Pow(float64(s), 2)
	}

	// Square root
	return math.Sqrt(sum / float64(len(samples)))
}
43217
func sumSquares(s metrics.Sample) float64 {
	count := float64(s.Count())
	sumSquared := math.Pow(count*s.Mean(), 2)
	sumSquares := math.Pow(count*s.StdDev(), 2) + sumSquared/count
	if math.IsNaN(sumSquares) {
		return 0.0
	}
	return sumSquares
}
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
}
776863
func Sqrt(real []float64) []float64 {
	var outBegIdx C.int
	var outNBElement C.int
	outReal := make([]float64, len(real))
	C.TA_SQRT(0, C.int(len(real)-1), (*C.double)(unsafe.Pointer(&real[0])), &outBegIdx, &outNBElement, (*C.double)(unsafe.Pointer(&outReal[0])))
	return outReal[:outNBElement]
}
1073225
func ErrFromP(p int) float64 {
	return 1.04 / math.Sqrt(math.Pow(2, float64(p)))
}
1230125
func Sqrt(z, x *decimal.Big) *decimal.Big {
	if z.CheckNaNs(x, nil) {
		return z
	}

	ideal := -((-x.Scale() - (-x.Scale() & 1)) / 2)
	if xs := x.Sign(); xs <= 0 {
		if xs == 0 {
			return z.SetMantScale(0, ideal).CopySign(z, x)
		}
		z.Context.Conditions |= decimal.InvalidOperation
		return z.SetNaN(false)
	}

	// Already checked for negative numbers.
	if x.IsInf(+1) {
		return z.SetInf(false)
	}

	var (
		prec = precision(z)
		ctx  = decimal.Context{Precision: prec}
		rnd  = z.Context.Conditions&decimal.Rounded != 0
		ixt  = z.Context.Conditions&decimal.Inexact != 0
	)

	// Source for the following algorithm:
	//
	//  T. E. Hull and A. Abrham. 1985. Properly rounded variable precision
	//  square root. ACM Trans. Math. Softw. 11, 3 (September 1985), 229-237.
	//  DOI: https://doi.org/10.1145/214408.214413

	var (
		xprec = x.Precision()

		// The algorithm requires a normalized ``f ∈ [0.1, 1)'' Of the two ways
		// to normalize f, adjusting its scale is the quickest. However, it then
		// requires us to increment approx's scale by e/2 instead of simply
		// setting it to e/2.
		f = new(decimal.Big).Copy(x).SetScale(xprec)
		e = -x.Scale() + xprec

		tmp decimal.Big // scratch space
	)

	if e&1 == 0 {
		ctx.FMA(z, approx2, f, approx1) // approx := .259 + .819f
	} else {
		f.SetScale(f.Scale() + 1)       // f := f/10
		e++                             // e := e + 1
		ctx.FMA(z, approx4, f, approx3) // approx := .0819 + 2.59f
	}

	maxp := prec + 5 // extra prec to skip weird +/- 0.5 adjustments
	ctx.Precision = 3
	for {
		// p := min(2*p - 2, maxp)
		ctx.Precision = min(2*ctx.Precision-2, maxp)

		// approx := .5*(approx + f/approx)
		ctx.Mul(z, ptFive, ctx.Add(&tmp, z, ctx.Quo(&tmp, f, z)))
		if ctx.Precision == maxp {
			break
		}
	}

	// The paper also specifies an additional code block for adjusting approx.
	// This code never went into the branches that modified approx, and rounding
	// to half even does the same thing. The GDA spec requires us to use
	// rounding mode half even (speleotrove.com/decimal/daops.html#refsqrt)
	// anyway.

	ctx.Reduce(z.SetScale(z.Scale() - e/2))
	if z.Precision() <= prec {
		if !rnd {
			z.Context.Conditions &= ^decimal.Rounded
		}
		if !ixt {
			z.Context.Conditions &= ^decimal.Inexact
		}
	}
	ctx.Precision = prec
	return ctx.Round(z)
}
755143
func DistanceSquared(p1, p2 orb.Point) float64 {
	d0 := (p1[0] - p2[0])
	d1 := (p1[1] - p2[1])
	return d0*d0 + d1*d1
}