// Asin returns the arcsine, in radians, of x.
//
// Range:
//     Input: -1 <= x <= 1
//     Output: -pi/2 <= Asin(x) <= pi/2
//
// Special cases:
//		Asin(NaN)  = NaN
//		Asin(±Inf) = NaN
//		Asin(x)    = NaN if x < -1 or x > 1
//		Asin(±1)   = ±pi/2
431842
func Asin(z, x *decimal.Big) *decimal.Big {
	if z.CheckNaNs(x, nil) {
		return z
	}

	cmp1 := x.CmpAbs(one)
	if x.IsInf(0) || cmp1 > 0 {
		z.Context.Conditions |= decimal.InvalidOperation
		return z.SetNaN(false)
	}

	ctx := decimal.Context{Precision: precision(z)}

	if cmp1 == 0 {
		pi2(z, ctx)
		if x.Signbit() {
			misc.SetSignbit(z, true)
		}
		return z
	}

	ctx.Precision += defaultExtraPrecision

	// Asin(x) = 2 * atan(x / (1 + sqrt(1 - x*x)))

	x2 := ctx.Mul(alias(z, x), x, x)
	ctx.Quo(x2, x, ctx.Add(x2, Sqrt(x2, ctx.Sub(x2, one, x2)), one))
	z.Copy(Atan(decimal.WithContext(ctx), x2))
	ctx.Mul(z, z, two)
	ctx.Precision -= defaultExtraPrecision
	return ctx.Round(z)
}
350024
func (as ArraySpec) Sin() Input {
	return as.proc(func(i Input) Input {
		return i.Sin()
	})
}
974328
func (u *Ugen) Atan2(val Input) Input {
	return binOpAtan2(u.Rate, u, val, u.NumOutputs)
}
742015
func Haversine(lat1, lng1, lat2, lng2 float64) float64 {
	phi1 := lat1 * (degreesToRadians)
	phi2 := lat2 * (degreesToRadians)
	deltaPhi := (lat2 - lat1) * (degreesToRadians)
	deltaLambda := (lng2 - lng1) * (degreesToRadians)

	v1 := math.Sin(deltaPhi / 2)
	v2 := math.Sin(deltaLambda / 2)
	a := v1*v1 + math.Cos(phi1)*math.Cos(phi2)*v2*v2
	c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))

	return earthRadius * c
}
1239493
func IdentN(dst *MatMxN, n int) *MatMxN {
	dst = dst.Reshape(n, n)

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				dst.Set(i, j, 1)
			} else {
				dst.Set(i, j, 0)
			}
		}
	}

	return dst
}
530888
func sin2Distance(x, y Point) (sin2, err float64) {
	// The (x-y).Cross(x+y) trick eliminates almost all of error due to x
	// and y being not quite unit length. This method is extremely accurate
	// for small distances; the *relative* error in the result is O(dblError) for
	// distances as small as dblError.
	n := x.Sub(y.Vector).Cross(x.Add(y.Vector))
	sin2 = 0.25 * n.Norm2()
	err = ((21+4*math.Sqrt(3))*dblError*sin2 +
		32*math.Sqrt(3)*dblError*dblError*math.Sqrt(sin2) +
		768*dblError*dblError*dblError*dblError)
	return sin2, err
}
389749
func IntOperand(x ast.Value, pos int) (int, error) {
	n, ok := x.(ast.Number)
	if !ok {
		return 0, NewOperandTypeErr(pos, x, "number")
	}

	i, ok := n.Int()
	if !ok {
		return 0, NewOperandErr(pos, "must be integer number but got floating-point number")
	}

	return i, nil
}
40924
func Cosine(x, y Vector) (float64, error) {
	d, err := DotProduct(x, y)
	if err != nil {
		return NA, err
	}

	xnorm := Norm(x, 2.0)
	ynorm := Norm(y, 2.0)

	return d / (xnorm * ynorm), nil
}
504082
func interpolationFuncMin() ast.Function {
	return ast.Function{
		ArgTypes:     []ast.Type{ast.TypeFloat},
		ReturnType:   ast.TypeFloat,
		Variadic:     true,
		VariadicType: ast.TypeFloat,
		Callback: func(args []interface{}) (interface{}, error) {
			min := args[0].(float64)

			for i := 1; i < len(args); i++ {
				min = math.Min(min, args[i].(float64))
			}

			return min, nil
		},
	}
}
1221621
public static BigFloat asin(BigFloat x) {
		if (x.isZero())
			return x;
		return x.isNaN() || (!isRangeAbs1(x)) ? NaN :
				x.context.valueOf(BigDecimalMath.asin(x.value, x.context.mathContext));
	}
115579
func (as ArraySpec) Cos() Input {
	return as.proc(func(i Input) Input {
		return i.Cos()
	})
}
834562
func Distance(p1, p2 orb.Point) float64 {
	dLat := deg2rad(p1[1] - p2[1])
	dLon := deg2rad(p1[0] - p2[0])

	dLon = math.Abs(dLon)
	if dLon > math.Pi {
		dLon = 2*math.Pi - dLon
	}

	// fast way using pythagorean theorem on an equirectangular projection
	x := dLon * math.Cos(deg2rad((p1[1]+p2[1])/2.0))
	return math.Sqrt(dLat*dLat+x*x) * orb.EarthRadius
}
418106
func (b *PCMBuffer) AsInt() (out []int) {
	int32s := b.AsI32()
	out = make([]int, len(int32s))
	for i := 0; i < len(int32s); i++ {
		out[i] = int(int32s[i])
	}
	return out
}
166132
func InterpolateAtDistance(ax s1.Angle, a, b Point) Point {
	aRad := ax.Radians()

	// Use PointCross to compute the tangent vector at A towards B. The
	// result is always perpendicular to A, even if A=B or A=-B, but it is not
	// necessarily unit length. (We effectively normalize it below.)
	normal := a.PointCross(b)
	tangent := normal.Vector.Cross(a.Vector)

	// Now compute the appropriate linear combination of A and "tangent". With
	// infinite precision the result would always be unit length, but we
	// normalize it anyway to ensure that the error is within acceptable bounds.
	// (Otherwise errors can build up when the result of one interpolation is
	// fed into another interpolation.)
	return Point{(a.Mul(math.Cos(aRad)).Add(tangent.Mul(math.Sin(aRad) / tangent.Norm()))).Normalize()}
}
338345
func (c C) Atan() Input {
	return C(float32(math.Atan(float64(c))))
}
183367
func latitude(p Point) s1.Angle {
	return s1.Angle(math.Atan2(p.Z, math.Sqrt(p.X*p.X+p.Y*p.Y))) * s1.Radian
}
818524
func RotateRight(x uint, k int) uint {
	if UintSize == 32 {
		return uint(RotateRight32(uint32(x), k))
	}
	return uint(RotateRight64(uint64(x), k))
}