// ToFloat returns a float or NaN.
972405
func ToFloat(v interface{}) float64 {
	switch n := v.(type) {
	case int:
		return float64(n)
	case int8:
		return float64(n)
	case int16:
		return float64(n)
	case int32:
		return float64(n)
	case int64:
		return float64(n)
	case uint:
		return float64(n)
	case uint8:
		return float64(n)
	case uint16:
		return float64(n)
	case uint32:
		return float64(n)
	case uint64:
		return float64(n)
	case float32:
		return float64(n)
	case float64:
		return n
	default:
		return math.NaN()
	}
}
707386
func toFloat(v reflect.Value) (float64, error) {
	switch v.Kind() {
	case reflect.Float32, reflect.Float64:
		return v.Float(), nil
	case reflect.Interface:
		return toFloat(v.Elem())
	}
	return -1, errors.New("unable to convert value to float")
}
522513
func MustFloat(input interface{}) float64 {
	output, err := Float(input)
	if err != nil {
		panic(err)
	}
	return output
}
478859
func asFloat(param string) float64 {

	i, err := strconv.ParseFloat(param, 64)
	panicIf(err)

	return i
}
1245655
func ConvertFloatToInt(fval float64, lowerBound, upperBound int64, tp byte) (int64, error) {
	val := RoundFloat(fval)
	if val < float64(lowerBound) {
		return lowerBound, overflow(val, tp)
	}

	if val >= float64(upperBound) {
		if val == float64(upperBound) {
			return upperBound, nil
		}
		return upperBound, overflow(val, tp)
	}
	return int64(val), nil
}
208395
func getFloat(unk interface{}) float64 {
	switch i := unk.(type) {
	case float64:
		return i
	case string:
		f, err := strconv.ParseFloat(i, 64)
		if err != nil || math.IsNaN(f) {
			return float64(0)
		}
		return f
	default:
		return float64(0)
	}
}
1245253
func (primative *Primative) AsFloat() (float64, error) {
	switch val := primative.value.(type) {
	case bool:
		floatVal := float64(0)
		if val {
			floatVal = float64(1)
		}

		return floatVal, nil
	case float64:
		return val, nil
	case int64:
		return float64(val), nil
	case string:
		return strconv.ParseFloat(val, 64)
	}

	msg := fmt.Sprintf("Could not convert value %s to type FLOAT", primative.value)
	return 0, errors.New(msg)
}
1030998
func GetFloat(key string) (float64, error) {
	value, err := Get(key)
	if err != nil {
		return 0, err
	}
	switch v := value.(type) {
	case float64:
		return v, nil
	case float32:
		return float64(v), nil
	case int:
		return float64(v), nil
	case string:
		if floatVal, err := strconv.ParseFloat(v, 64); err == nil {
			return floatVal, nil
		}
	}
	return 0, &InvalidValue{key, "float"}
}
354774
func (ns *Namespace) ToFloat(v interface{}) (float64, error) {
	v = convertTemplateToString(v)
	return _cast.ToFloat64E(v)
}
649265
func (tr Row) ForceFloat(nn int) (val float64) {
	val, _ = tr.FloatErr(nn)
	return
}
1251337
func (list *List) GetFloat(idx int) (float64, error) {
	value, err := list.Get(idx)
	if err != nil {
		return float64(0), err
	}

	switch value.(type) {
	case *Primative:
		return value.(*Primative).AsFloat()
	}

	return float64(0), errors.New("could not convert non-primative value to float")
}
259857
func TruncateFloat(f float64, flen int, decimal int) (float64, error) {
	if math.IsNaN(f) {
		// nan returns 0
		return 0, ErrOverflow.GenWithStackByArgs("DOUBLE", "")
	}

	maxF := GetMaxFloat(flen, decimal)

	if !math.IsInf(f, 0) {
		f = Round(f, decimal)
	}

	var err error
	if f > maxF {
		f = maxF
		err = ErrOverflow.GenWithStackByArgs("DOUBLE", "")
	} else if f < -maxF {
		f = -maxF
		err = ErrOverflow.GenWithStackByArgs("DOUBLE", "")
	}

	return f, errors.Trace(err)
}
1055233
func (feature *Feature) PropertyFloat(propertyName string) float64 {
	var result = math.NaN()
	if property, ok := feature.Properties[propertyName]; ok {
		result = floatify(property)
	}
	return result
}
455814
func (c Config) GetFloat(key string) (float64, error) {
	var (
		fout float64
		val  interface{}
		ok   bool
	)

	if val, ok = c[key]; !ok {
		return fout, ErrConfigNotFound
	}

	if fout, ok = val.(float64); !ok {
		return fout, ErrNotAFloat
	}

	return fout, nil
}
556561
func ToFloat(value interface{}) float64 {
	if result := ToString(value); result == "" {
		return 0
	} else if i, err := strconv.ParseFloat(result, 64); err == nil {
		return i
	} else {
		panic("failed to parse float: " + result)
	}
}
286205
func ToFloat(str string) (float64, error) {
	res, err := strconv.ParseFloat(str, 64)
	if err != nil {
		res = 0.0
	}
	return res, err
}
157560
func AppendFloat(dst EncodingBuffer, val float64, fmt byte, prec, bitSize int) {
	var bits uint64
	var flt *floatInfo
	switch bitSize {
	case 32:
		bits = uint64(math.Float32bits(float32(val)))
		flt = &float32info
	case 64:
		bits = math.Float64bits(val)
		flt = &float64info
	default:
		panic("strconv: illegal AppendFloat/FormatFloat bitSize")
	}

	neg := bits>>(flt.expbits+flt.mantbits) != 0
	exp := int(bits>>flt.mantbits) & (1<<flt.expbits - 1)
	mant := bits & (uint64(1)<<flt.mantbits - 1)

	switch exp {
	case 1<<flt.expbits - 1:
		// Inf, NaN
		var s string
		switch {
		case mant != 0:
			s = "NaN"
		case neg:
			s = "-Inf"
		default:
			s = "+Inf"
		}
		dst.WriteString(s)
		return

	case 0:
		// denormalized
		exp++

	default:
		// add implicit top bit
		mant |= uint64(1) << flt.mantbits
	}
	exp += flt.bias

	// Pick off easy binary format.
	if fmt == 'b' {
		fmtB(dst, neg, mant, exp, flt)
		return
	}

	if !optimize {
		bigFtoa(dst, prec, fmt, neg, mant, exp, flt)
		return
	}

	var digs decimalSlice
	ok := false
	// Negative precision means "only as much as needed to be exact."
	shortest := prec < 0
	if shortest {
		// Try Grisu3 algorithm.
		f := new(extFloat)
		lower, upper := f.AssignComputeBounds(mant, exp, neg, flt)
		var buf [32]byte
		digs.d = buf[:]
		ok = f.ShortestDecimal(&digs, &lower, &upper)
		if !ok {
			bigFtoa(dst, prec, fmt, neg, mant, exp, flt)
			return
		}
		// Precision for shortest representation mode.
		switch fmt {
		case 'e', 'E':
			prec = max(digs.nd-1, 0)
		case 'f':
			prec = max(digs.nd-digs.dp, 0)
		case 'g', 'G':
			prec = digs.nd
		}
	} else if fmt != 'f' {
		// Fixed number of digits.
		digits := prec
		switch fmt {
		case 'e', 'E':
			digits++
		case 'g', 'G':
			if prec == 0 {
				prec = 1
			}
			digits = prec
		}
		if digits <= 15 {
			// try fast algorithm when the number of digits is reasonable.
			var buf [24]byte
			digs.d = buf[:]
			f := extFloat{mant, exp - int(flt.mantbits), neg}
			ok = f.FixedDecimal(&digs, digits)
		}
	}
	if !ok {
		bigFtoa(dst, prec, fmt, neg, mant, exp, flt)
		return
	}
	formatDigits(dst, shortest, neg, digs, prec, fmt)
	return
}