// ConvertFloatToUint converts a float value to an uint value.
969237
func ConvertFloatToUint(sc *stmtctx.StatementContext, fval float64, upperBound uint64, tp byte) (uint64, error) {
	val := RoundFloat(fval)
	if val < 0 {
		if sc.ShouldClipToZero() {
			return 0, overflow(val, tp)
		}
		return uint64(int64(val)), overflow(val, tp)
	}

	if val > float64(upperBound) {
		return upperBound, overflow(val, tp)
	}
	return uint64(val), nil
}
426478
func (be *BinaryEncoder) WriteFloat(x float32) {
	bytes := make([]byte, 4)
	binary.LittleEndian.PutUint32(bytes, math.Float32bits(x))
	_, _ = be.buffer.Write(bytes)
}
961151
func NewFloatConvertFilter() *FloatConvertFilter {
	ret := &FloatConvertFilter{
		make([]base.Attribute, 0),
		make([]base.FilteredAttribute, 0),
		make(map[base.Attribute]bool),
		make(map[base.Attribute]map[uint64]base.Attribute),
	}
	return ret
}
22765
func (v *Value) Float() float64 {
	switch v.getResolvedValue().Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return float64(v.getResolvedValue().Int())
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		return float64(v.getResolvedValue().Uint())
	case reflect.Float32, reflect.Float64:
		return v.getResolvedValue().Float()
	case reflect.String:
		// Try to convert from string to float64 (base 10)
		f, err := strconv.ParseFloat(v.getResolvedValue().String(), 64)
		if err != nil {
			return 0.0
		}
		return f
	default:
		logf("Value.Float() not available for type: %s\n", v.getResolvedValue().Kind().String())
		return 0.0
	}
}
103719
func IEEEFloatToInt(b [10]byte) int {
	var i uint32
	// Negative number
	if (b[0] & 0x80) == 1 {
		return 0
	}

	// Less than 1
	if b[0] <= 0x3F {
		return 1
	}

	// Too big
	if b[0] > 0x40 {
		return 67108864
	}

	// Still too big
	if b[0] == 0x40 && b[1] > 0x1C {
		return 800000000
	}

	i = (uint32(b[2]) << 23) | (uint32(b[3]) << 15) | (uint32(b[4]) << 7) | (uint32(b[5]) >> 1)
	i >>= (29 - uint32(b[1]))

	return int(i)
}
414972
func NumberToFloat(n ast.Number) *big.Float {
	r, ok := new(big.Float).SetString(string(n))
	if !ok {
		panic("illegal value")
	}
	return r
}
908065
func stringValToUint(val string) (uint, error) {
	parsedField, err := strconv.ParseUint(val, 10, 64)
	if err != nil {
		splitErr := strings.Split(err.Error(), ": ")
		errStr := splitErr[len(splitErr)-1]
		// return a value of zero and the error encountered during string parsing
		return 0, fmt.Errorf("Value '%v' cannot be parsed as an unsigned integer (%v)", val, errStr)
	}
	// return the unsigned integer equivalent of the input string and a nil error (indicating success)
	return uint(parsedField), nil
}
491534
func FloatValue(val string) (*wrappers.FloatValue, error) {
	parsedVal, err := Float32(val)
	return &wrappers.FloatValue{Value: parsedVal}, err
}
1026051
func ToFloat64(x interface{}) (float64, bool) {
	var xf float64
	xok := true

	switch xn := x.(type) {
	case uint8:
		xf = float64(xn)
	case uint16:
		xf = float64(xn)
	case uint32:
		xf = float64(xn)
	case uint64:
		xf = float64(xn)
	case int:
		xf = float64(xn)
	case int8:
		xf = float64(xn)
	case int16:
		xf = float64(xn)
	case int32:
		xf = float64(xn)
	case int64:
		xf = float64(xn)
	case float32:
		xf = float64(xn)
	case float64:
		xf = float64(xn)
	default:
		xok = false
	}

	return xf, xok
}
203548
func ConvertIntToUint(sc *stmtctx.StatementContext, val int64, upperBound uint64, tp byte) (uint64, error) {
	if sc.ShouldClipToZero() && val < 0 {
		return 0, overflow(val, tp)
	}

	if uint64(val) > upperBound {
		return upperBound, overflow(val, tp)
	}

	return uint64(val), nil
}
1364334
func keyFloat(v reflect.Value) (f float64, ok bool) {
	switch v.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return float64(v.Int()), true
	case reflect.Float32, reflect.Float64:
		return v.Float(), true
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		return float64(v.Uint()), true
	case reflect.Bool:
		if v.Bool() {
			return 1, true
		}
		return 0, true
	}
	return 0, false
}
1103523
func coerceToFloat(unk interface{}) (float64, error) {
	switch i := unk.(type) {
	case float64:
		if math.IsNaN(i) {
			return i, errors.New("value was NaN")
		}
		return i, nil
	case float32:
		return float64(i), nil
	case int:
		return float64(i), nil
	case int32:
		return float64(i), nil
	case int64:
		return float64(i), nil
	case uint:
		return float64(i), nil
	case uint32:
		return float64(i), nil
	case uint64:
		return float64(i), nil
	default:
		return math.NaN(), fmt.Errorf("value %q could not be coerced to float64", i)
	}
}
391377
func (d *adxl345DataFormat) ConvertToSI(rawValue int16) float64 {
	switch d.sensorRange {
	case ADXL345_RANGE_2G:
		return float64(rawValue) * 2 / 512
	case ADXL345_RANGE_4G:
		return float64(rawValue) * 4 / 512
	case ADXL345_RANGE_8G:
		return float64(rawValue) * 8 / 512
	case ADXL345_RANGE_16G:
		return float64(rawValue) * 16 / 512
	default:
		return 0
	}
}
755271
func DecodeFloat(b []byte) ([]byte, float64, error) {
	b, u, err := DecodeUint(b)
	return b, decodeCmpUintToFloat(u), errors.Trace(err)
}
296200
func TimeToFloat(t time.Time) float64 {
	return float64(t.Unix()) + (float64(t.Nanosecond()) / 1e9)
}
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)
}
379724
func ConvertProtoStatValue(in *proto.StatValue) *StatValue {
	if in == nil {
		return nil
	}

	return &StatValue{
		FloatNumeratorVal:   unwrapDouble(in.FloatNumeratorVal),
		FloatDenominatorVal: unwrapDouble(in.FloatDenominatorVal),
		IntNumeratorVal:     unwrapInt64(in.IntNumeratorVal),
		IntDenominatorVal:   unwrapInt64(in.IntDenominatorVal),
		StringVal:           unwrapString(in.StringVal),
		BoolVal:             unwrapBool(in.BoolVal),
		Unit:                in.Unit,
		Desc:                in.Desc,
	}
}