// FloatValue well-known type support as wrapper around float32 type
491534
func FloatValue(val string) (*wrappers.FloatValue, error) {
	parsedVal, err := Float32(val)
	return &wrappers.FloatValue{Value: parsedVal}, err
}
1232680
func CastValue(ctx context.Context, val types.Datum, col *model.ColumnInfo) (casted types.Datum, err error) {
	casted, err = val.ConvertTo(ctx.GetSessionVars().StmtCtx, &col.FieldType)
	if err != nil {
		if ctx.GetSessionVars().StrictSQLMode {
			return casted, errors.Trace(err)
		}
		// TODO: add warnings.
		log.Printf("cast value error %v", err)
	}
	return casted, nil
}
308881
func (f *Queries) Float32(key string) (float32, error) {
	s, err := f.String(key)
	if err != nil {
		return 0, err
	}
	v, err := strconv.ParseFloat(s, 64)
	return float32(v), err
}
992498
func (p *point) FloatValue() (float64, error) {
	f, err := parseFloatBytes(p.it.valueBuf, 64)
	if err != nil {
		return 0, fmt.Errorf("unable to parse floating point value %q: %v", p.it.valueBuf, err)
	}
	return f, nil
}
903815
func (c Context) Float32(key string, f float32) Context {
	c.l.context = enc.AppendFloat32(enc.AppendKey(c.l.context, key), f)
	return c
}
879388
func DoubleValue(val string) (*wrappers.DoubleValue, error) {
	parsedVal, err := Float64(val)
	return &wrappers.DoubleValue{Value: parsedVal}, err
}
659311
func Float(v interface{}, err error) (float64, error) {
	if err != nil {
		return 0.0, err
	}

	vf, ok := v.(float64)
	if ok {
		return vf, nil
	}

	return 0.0, newWrongTypeError(v, vf)
}
1001994
func (value Value) toReflectValue(kind reflect.Kind) (reflect.Value, error) {
	if kind != reflect.Float32 && kind != reflect.Float64 && kind != reflect.Interface {
		switch value := value.value.(type) {
		case float32:
			_, frac := math.Modf(float64(value))
			if frac > 0 {
				return reflect.Value{}, fmt.Errorf("RangeError: %v to reflect.Kind: %v", value, kind)
			}
		case float64:
			_, frac := math.Modf(value)
			if frac > 0 {
				return reflect.Value{}, fmt.Errorf("RangeError: %v to reflect.Kind: %v", value, kind)
			}
		}
	}

	switch kind {
	case reflect.Bool: // Bool
		return reflect.ValueOf(value.bool()), nil
	case reflect.Int: // Int
		// We convert to float64 here because converting to int64 will not tell us
		// if a value is outside the range of int64
		tmp := toIntegerFloat(value)
		if tmp < float_minInt || tmp > float_maxInt {
			return reflect.Value{}, fmt.Errorf("RangeError: %f (%v) to int", tmp, value)
		} else {
			return reflect.ValueOf(int(tmp)), nil
		}
	case reflect.Int8: // Int8
		tmp := value.number().int64
		if tmp < int64_minInt8 || tmp > int64_maxInt8 {
			return reflect.Value{}, fmt.Errorf("RangeError: %d (%v) to int8", tmp, value)
		} else {
			return reflect.ValueOf(int8(tmp)), nil
		}
	case reflect.Int16: // Int16
		tmp := value.number().int64
		if tmp < int64_minInt16 || tmp > int64_maxInt16 {
			return reflect.Value{}, fmt.Errorf("RangeError: %d (%v) to int16", tmp, value)
		} else {
			return reflect.ValueOf(int16(tmp)), nil
		}
	case reflect.Int32: // Int32
		tmp := value.number().int64
		if tmp < int64_minInt32 || tmp > int64_maxInt32 {
			return reflect.Value{}, fmt.Errorf("RangeError: %d (%v) to int32", tmp, value)
		} else {
			return reflect.ValueOf(int32(tmp)), nil
		}
	case reflect.Int64: // Int64
		// We convert to float64 here because converting to int64 will not tell us
		// if a value is outside the range of int64
		tmp := toIntegerFloat(value)
		if tmp < float_minInt64 || tmp > float_maxInt64 {
			return reflect.Value{}, fmt.Errorf("RangeError: %f (%v) to int", tmp, value)
		} else {
			return reflect.ValueOf(int64(tmp)), nil
		}
	case reflect.Uint: // Uint
		// We convert to float64 here because converting to int64 will not tell us
		// if a value is outside the range of uint
		tmp := toIntegerFloat(value)
		if tmp < 0 || tmp > float_maxUint {
			return reflect.Value{}, fmt.Errorf("RangeError: %f (%v) to uint", tmp, value)
		} else {
			return reflect.ValueOf(uint(tmp)), nil
		}
	case reflect.Uint8: // Uint8
		tmp := value.number().int64
		if tmp < 0 || tmp > int64_maxUint8 {
			return reflect.Value{}, fmt.Errorf("RangeError: %d (%v) to uint8", tmp, value)
		} else {
			return reflect.ValueOf(uint8(tmp)), nil
		}
	case reflect.Uint16: // Uint16
		tmp := value.number().int64
		if tmp < 0 || tmp > int64_maxUint16 {
			return reflect.Value{}, fmt.Errorf("RangeError: %d (%v) to uint16", tmp, value)
		} else {
			return reflect.ValueOf(uint16(tmp)), nil
		}
	case reflect.Uint32: // Uint32
		tmp := value.number().int64
		if tmp < 0 || tmp > int64_maxUint32 {
			return reflect.Value{}, fmt.Errorf("RangeError: %d (%v) to uint32", tmp, value)
		} else {
			return reflect.ValueOf(uint32(tmp)), nil
		}
	case reflect.Uint64: // Uint64
		// We convert to float64 here because converting to int64 will not tell us
		// if a value is outside the range of uint64
		tmp := toIntegerFloat(value)
		if tmp < 0 || tmp > float_maxUint64 {
			return reflect.Value{}, fmt.Errorf("RangeError: %f (%v) to uint64", tmp, value)
		} else {
			return reflect.ValueOf(uint64(tmp)), nil
		}
	case reflect.Float32: // Float32
		tmp := value.float64()
		tmp1 := tmp
		if 0 > tmp1 {
			tmp1 = -tmp1
		}
		if tmp1 > 0 && (tmp1 < math.SmallestNonzeroFloat32 || tmp1 > math.MaxFloat32) {
			return reflect.Value{}, fmt.Errorf("RangeError: %f (%v) to float32", tmp, value)
		} else {
			return reflect.ValueOf(float32(tmp)), nil
		}
	case reflect.Float64: // Float64
		value := value.float64()
		return reflect.ValueOf(float64(value)), nil
	case reflect.String: // String
		return reflect.ValueOf(value.string()), nil
	case reflect.Invalid: // Invalid
	case reflect.Complex64: // FIXME? Complex64
	case reflect.Complex128: // FIXME? Complex128
	case reflect.Chan: // FIXME? Chan
	case reflect.Func: // FIXME? Func
	case reflect.Ptr: // FIXME? Ptr
	case reflect.UnsafePointer: // FIXME? UnsafePointer
	default:
		switch value.kind {
		case valueObject:
			object := value._object()
			switch vl := object.value.(type) {
			case *_goStructObject: // Struct
				return reflect.ValueOf(vl.value.Interface()), nil
			case *_goMapObject: // Map
				return reflect.ValueOf(vl.value.Interface()), nil
			case *_goArrayObject: // Array
				return reflect.ValueOf(vl.value.Interface()), nil
			case *_goSliceObject: // Slice
				return reflect.ValueOf(vl.value.Interface()), nil
			}
			return reflect.ValueOf(value.exportNative()), nil
		case valueEmpty, valueResult, valueReference:
			// These are invalid, and should panic
		default:
			return reflect.ValueOf(value.value), nil
		}
	}

	// FIXME Should this end up as a TypeError?
	panic(fmt.Errorf("invalid conversion of %v (%v) to reflect.Kind: %v", value.kind, value, kind))
}
1176579
func (dt *DbfTable) Float64FieldValueByName(row int, fieldName string) (value float64, err error) {
	valueAsString, err := dt.FieldValueByName(row, fieldName)
	return strconv.ParseFloat(valueAsString, 64)
}
211314
func reflectValue(valueType string, value interface{}) (reflect.Value, error) {
	theType, ok := typesMap[valueType]
	if !ok {
		return reflect.Value{}, NewErrUnsupportedType(valueType)
	}
	theValue := reflect.New(theType)

	// Booleans
	if theType.String() == "bool" {
		boolValue, err := getBoolValue(theType.String(), value)
		if err != nil {
			return reflect.Value{}, err
		}

		theValue.Elem().SetBool(boolValue)
		return theValue.Elem(), nil
	}

	// Integers
	if strings.HasPrefix(theType.String(), "int") {
		intValue, err := getIntValue(theType.String(), value)
		if err != nil {
			return reflect.Value{}, err
		}

		theValue.Elem().SetInt(intValue)
		return theValue.Elem(), err
	}

	// Unsigned integers
	if strings.HasPrefix(theType.String(), "uint") {
		uintValue, err := getUintValue(theType.String(), value)
		if err != nil {
			return reflect.Value{}, err
		}

		theValue.Elem().SetUint(uintValue)
		return theValue.Elem(), err
	}

	// Floating point numbers
	if strings.HasPrefix(theType.String(), "float") {
		floatValue, err := getFloatValue(theType.String(), value)
		if err != nil {
			return reflect.Value{}, err
		}

		theValue.Elem().SetFloat(floatValue)
		return theValue.Elem(), err
	}

	// Strings
	if theType.String() == "string" {
		stringValue, err := getStringValue(theType.String(), value)
		if err != nil {
			return reflect.Value{}, err
		}

		theValue.Elem().SetString(stringValue)
		return theValue.Elem(), nil
	}

	return reflect.Value{}, NewErrUnsupportedType(valueType)
}
1327202
func AsValue(v interface{}) (out Value, ok bool) {
	if v == nil {
		return nil, true
	}
	switch v := v.(type) {
	case Value:
		out = v
	case string:
		out = String(v)
	case int:
		out = Int(v)
	case int8:
		out = Int(v)
	case int16:
		out = Int(v)
	case int32:
		out = Int(v)
	case int64:
		out = Int(v)
	case uint:
		out = Int(v)
	case uint8:
		out = Int(v)
	case uint16:
		out = Int(v)
	case uint32:
		out = Int(v)
	case uint64:
		out = Int(v)
	case float64:
		out = Float(v)
	case float32:
		out = Float(v)
	case bool:
		out = Bool(v)
	case time.Time:
		out = Time(v)
	default:
		return nil, false
	}
	return out, true
}
509234
func (s *Session) Float32(key string) float32 {
	s.RLock()
	defer s.RUnlock()

	v, ok := s.data[key]
	if !ok {
		return 0
	}

	value, ok := v.(float32)
	if !ok {
		return 0
	}
	return value
}
522559
func toFloat64(v interface{}) float64 {
	if str, ok := v.(string); ok {
		iv, err := strconv.ParseFloat(str, 64)
		if err != nil {
			return 0
		}
		return iv
	}

	val := reflect.Indirect(reflect.ValueOf(v))
	switch val.Kind() {
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		return float64(val.Int())
	case reflect.Uint8, reflect.Uint16, reflect.Uint32:
		return float64(val.Uint())
	case reflect.Uint, reflect.Uint64:
		return float64(val.Uint())
	case reflect.Float32, reflect.Float64:
		return val.Float()
	case reflect.Bool:
		if val.Bool() == true {
			return 1
		}
		return 0
	default:
		return 0
	}
}
579244
func AsFloat(d DataType) (float64, bool) {
	value, ok := d.Value().(float64)
	return value, ok
}
973642
func (p *parserMixin) Float32() (target *float32) {
	target = new(float32)
	p.Float32Var(target)
	return
}
1301249
func (c *Cell) Float() (float64, error) {
	f, err := strconv.ParseFloat(c.Value, 64)
	if err != nil {
		return math.NaN(), err
	}
	return f, nil
}
372593
func (d *defaulter) AsFloat64(v Valuer, dv float64) float64 {
	value, err := v.Value()
	if err != nil {
		d.logValuerError(err)
		return dv
	}
	fvalue, err := strconv.ParseFloat(value, 64)
	if err != nil {
		d.logFormatError("float64", err)
		return dv
	}
	return fvalue
}