// stToSiTi converts the s- or t-value to the nearest si- or ti-coordinate.
// The result may be outside the range of valid (si,ti)-values. Value of
// 0.49999999999999994 (math.NextAfter(0.5, -1)), will be incorrectly rounded up.
554501
func stToSiTi(s float64) uint32 {
	if s < 0 {
		return uint32(s*maxSiTi - 0.5)
	}
	return uint32(s*maxSiTi + 0.5)
}
1228479
func ValueToFloat64(val Value) (float64, bool) {
	if val == nil || val.Nil() || val.Err() {
		return math.NaN(), false
	}
	switch v := val.(type) {
	case NumericValue:
		return v.Float(), true
	case StringValue:
		return StringToFloat64(v.Val())
	case BoolValue:
		// Should we co-erce bools to 0/1?
		if v.Val() {
			return float64(1), true
		}
		return float64(0), true
	}
	return math.NaN(), false
}
319249
func stoi(s string) int64 {
	ret, err := strconv.ParseUint(s, 32, 64)
	if err != nil {
		//TODO handle error?
		return 0
	}
	return int64(ret - int64Adjust)
}
1284945
func pi(z *decimal.Big, ctx decimal.Context) *decimal.Big {
	if ctx.Precision <= constPrec {
		return ctx.Set(z, _Pi)
	}

	var (
		lasts = new(decimal.Big)
		t     = new(decimal.Big).SetUint64(3)
		s     = z.SetUint64(3)
		n     = new(decimal.Big).SetUint64(1)
		na    = new(decimal.Big)
		d     = new(decimal.Big)
		da    = new(decimal.Big).SetUint64(24)
	)

	for s.Cmp(lasts) != 0 {
		lasts.Copy(s)
		ctx.Add(n, n, na)
		ctx.Add(na, na, eight)
		ctx.Add(d, d, da)
		ctx.Add(da, da, thirtyTwo)
		ctx.Mul(t, t, n)
		ctx.Quo(t, t, d)
		ctx.Add(s, s, t)
	}
	return ctx.Round(z) // z == s
}
1263395
func faceSiTiToXYZ(face int, si, ti uint32) Point {
	return Point{faceUVToXYZ(face, stToUV(siTiToST(si)), stToUV(siTiToST(ti)))}
}
293804
func (db *DB) STTL(key []byte) (int64, error) {
	if err := checkKeySize(key); err != nil {
		return -1, err
	}

	return db.ttl(SetType, key)
}
1016660
func UintValueSlice(src []*uint) []uint {
	dst := make([]uint, len(src))
	for i := 0; i < len(src); i++ {
		if src[i] != nil {
			dst[i] = *(src[i])
		}
	}
	return dst
}
1366155
func (v *Value) ToInt() (val int64, ok bool) {
	switch v.vType {
	case typeInt:
		val, ok = v.value.(int64)
	default:
	}
	return
}
409878
func NewValueI16(v int16) Value {
	return Value{
		typ:     TI16,
		tnumber: uint64(v),
	}
}
1016609
func NewStochRsi(timePeriod int, fastKTimePeriod int, fastDTimePeriod int) (indicator *StochRsi, err error) {
	newStochRsi := StochRsi{}
	newStochRsi.StochRsiWithoutStorage, err = NewStochRsiWithoutStorage(timePeriod, fastKTimePeriod, fastDTimePeriod,
		func(dataItemK float64, dataItemD float64, streamBarIndex int) {
			newStochRsi.SlowK = append(newStochRsi.SlowK, dataItemK)
			newStochRsi.SlowD = append(newStochRsi.SlowD, dataItemD)
		})

	return &newStochRsi, err
}
560083
func Uint64(val interface{}) uint64 {

	switch t := val.(type) {
	case int:
		return uint64(t)
	case int8:
		return uint64(t)
	case int16:
		return uint64(t)
	case int32:
		return uint64(t)
	case int64:
		return uint64(t)
	case uint:
		return uint64(t)
	case uint8:
		return uint64(t)
	case uint16:
		return uint64(t)
	case uint32:
		return uint64(t)
	case uint64:
		return uint64(t)
	case float32:
		return uint64(t)
	case float64:
		return uint64(t)
	case bool:
		if t == true {
			return uint64(1)
		}
		return uint64(0)
	default:
		i, _ := strconv.ParseUint(String(val), 10, 64)
		return i
	}

	panic("Reached")

}
671995
func IsTIF(src *sdl.RWops) bool {
	_src := (*C.SDL_RWops)(unsafe.Pointer(src))
	return int(C.IMG_isTIF(_src)) > 0
}
430009
func UInt32Value(val string) (*wrappers.UInt32Value, error) {
	parsedVal, err := Uint32(val)
	return &wrappers.UInt32Value{Value: parsedVal}, err
}
40273
func UnitsToPoints(t int, u float64) float64 {
	switch t {
	case Unit_PT:
		return u * conversion_Unit_PT
	case Unit_MM:
		return u * conversion_Unit_MM
	case Unit_CM:
		return u * conversion_Unit_CM
	case Unit_IN:
		return u * conversion_Unit_IN
	default:
		return u
	}
}
168844
func (met *Metrics) SubI(name string, value int) {
	atomic.AddInt64(met.get(name), int64(-value))
}
171662
func uvToST(u float64) float64 {
	if u >= 0 {
		return 0.5 * math.Sqrt(1+3*u)
	}
	return 1 - 0.5*math.Sqrt(1-3*u)
}
850437
func FlatTop(L int) []float64 {
	const (
		alpha0 = float64(0.21557895)
		alpha1 = float64(0.41663158)
		alpha2 = float64(0.277263158)
		alpha3 = float64(0.083578947)
		alpha4 = float64(0.006947368)
	)

	r := make([]float64, L)

	if L == 1 {
		r[0] = 1
		return r
	}

	N := L - 1
	coef := 2 * math.Pi / float64(N)

	for n := 0; n <= N; n++ {
		factor := float64(n) * coef

		term0 := alpha0
		term1 := alpha1 * math.Cos(factor)
		term2 := alpha2 * math.Cos(2*factor)
		term3 := alpha3 * math.Cos(3*factor)
		term4 := alpha4 * math.Cos(4*factor)

		r[n] = term0 - term1 + term2 - term3 + term4
	}

	return r
}