// cast - try to cast string values to bool or float64
519195
func cast(s string, r bool) interface{} {
	if r {
		// handle nan and inf
		if !castNanInf {
			switch strings.ToLower(s) {
			case "nan", "inf", "-inf":
				return interface{}(s)
			}
		}

		// handle numeric strings ahead of boolean
		if f, err := strconv.ParseFloat(s, 64); err == nil {
			return interface{}(f)
		}
		// ParseBool treats "1"==true & "0"==false
		// but be more strick - only allow TRUE, True, true, FALSE, False, false
		if s != "t" && s != "T" && s != "f" && s != "F" {
			if b, err := strconv.ParseBool(s); err == nil {
				return interface{}(b)
			}
		}
	}
	return interface{}(s)
}
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
	}
}
397253
func (x *Big) Float(z *big.Float) *big.Float {
	if debug {
		x.validate()
	}

	if z == nil {
		z = new(big.Float)
	}

	switch x.form {
	case finite, finite | signbit:
		if x.isZero() {
			z.SetUint64(0)
		} else {
			z.SetRat(x.Rat(nil))
		}
	case pinf, ninf:
		z.SetInf(x.form == pinf)
	default: // snan, qnan, ssnan, sqnan:
		z.SetUint64(0)
	}
	return z
}
634819
func ToFloat(value interface{}) (float64, error) {
	v := reflect.ValueOf(value)
	switch v.Kind() {
	case reflect.Float32, reflect.Float64:
		return v.Float(), nil
	}
	return 0, fmt.Errorf("cannot convert %v to float64", v.Kind())
}
743337
func ToFloat64(v interface{}) float64 {
	if str, ok := v.(string); ok {
		return strToFloat64(str)
	}

	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() {
			return 1
		}
		return 0
	default:
		return 0
	}
}
1301249
func (c *Cell) Float() (float64, error) {
	f, err := strconv.ParseFloat(c.Value, 64)
	if err != nil {
		return math.NaN(), err
	}
	return f, nil
}
1044210
func ToFloat(data interface{}) (float64, bool) {
	switch typed := data.(type) {
	case float64:
		return typed, true
	case float32:
		return float64(typed), true
	default:
		if n, ok := ToInt(data); ok {
			return float64(n), true
		}
		return 0, false
	}
}
565617
func (l *Literal) Float64() (float64, error) {
	if l.t != Float64 {
		return 0, fmt.Errorf("literal.Float64: literal is of type %v; cannot be converted to a float64", l.t)
	}
	return l.v.(float64), nil
}
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
}
842787
func String(input interface{}) (output string, err error) {

	switch castValue := input.(type) {
	case Stringer:
		output = castValue.String()
		return
	case string:
		output = string(castValue)
		return
	case []byte:
		output = string(castValue)
		return
	case int:
		output = strconv.Itoa(castValue)
		return
	case int8:
		output = strconv.Itoa(int(castValue))
		return
	case int16:
		output = strconv.Itoa(int(castValue))
		return
	case int32:
		output = strconv.Itoa(int(castValue))
		return
	case int64:
		output = strconv.FormatInt(castValue, 10)
		return
	case uint:
		output = strconv.FormatUint(uint64(castValue), 10)
		return
	case uint8:
		output = strconv.FormatUint(uint64(castValue), 10)
		return
	case uint16:
		output = strconv.FormatUint(uint64(castValue), 10)
		return
	case uint32:
		output = strconv.FormatUint(uint64(castValue), 10)
		return
	case uint64:
		output = strconv.FormatUint(uint64(castValue), 10)
		return
	case float32:
		// What exact value for perc value
		output = strconv.FormatFloat(float64(castValue), 'g', -1, 64)
		return
	case float64:
		// What exact value for perc value
		output = strconv.FormatFloat(castValue, 'g', -1, 64)
		return
	case nil:
		output = ""
		return
	case bool:
		output = strconv.FormatBool(castValue)
		return
	default:
		err = NewCastError("Could not convert to string")
	}
	return
}
1360636
func (num Number) Float64() (float64, bool) {
	f, err := json.Number(num).Float64()
	if err != nil {
		return 0, false
	}
	return f, true
}
1074851
func (mmap MarshalMap) Float(key string) (float64, error) {
	val, exists := mmap.Value(key)
	if !exists {
		return 0, fmt.Errorf(`"%s" is not set`, key)
	}

	if floatVal, isNumber := treflect.Float64(val); isNumber {
		return floatVal, nil
	}

	return 0, fmt.Errorf(`"%s" is expected to be a signed number type`, key)
}
315207
func castConstToTyped(from ConstType, c constValue, to reflect.Type, expr Expr) (
	constValue, []error) {
        return convertConstToTyped(from, c, to, true, expr)
}
30241
func Bool(input interface{}) (output bool, err error) {
	switch castValue := input.(type) {
	case Booler:
		output = castValue.Bool()
		return
	case string:
		var errParse error
		output, errParse = strconv.ParseBool(castValue)
		if errParse != nil && len(castValue) > 0 {
			output = true
		}
		return
	case int:
		if castValue != 0 {
			output = true
		}
		return
	case int8:
		if castValue != 0 {
			output = true
		}
		return
	case int16:
		if castValue != 0 {
			output = true
		}
		return
	case int32:
		if castValue != 0 {
			output = true
		}
		return
	case int64:
		if castValue != 0 {
			output = true
		}
		return
	case uint:
		if castValue != 0 {
			output = true
		}
		return
	case uint8:
		if castValue != 0 {
			output = true
		}
		return
	case uint16:
		if castValue != 0 {
			output = true
		}
		return
	case uint32:
		if castValue != 0 {
			output = true
		}
		return
	case uint64:
		if castValue != 0 {
			output = true
		}
		return
	case float32:
		if castValue != 0 {
			output = true
		}
		return
	case float64:
		if castValue != 0 {
			output = true
		}
		return
	case bool:
		output = castValue
		return
	case nil:
		output = false
		return
	default:
		err = NewCastError("Could not convert to bool")
	}
	return
}
1208111
func (i Int) Float() Float {
	// TODO(adonovan): opt: handle common values without allocation.
	f, _ := new(big.Float).SetInt(i.bigint).Float64()
	return Float(f)
}
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)
}
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)
	}
}