// FmtFloat yields a string representation of f. E.g. 12345.67 --> "12.3 k";  0.09876 --> "99 m"
553693
func FmtFloat(f float64) string {
	af := math.Abs(f)
	if f == 0 {
		return "0"
	} else if 1 <= af && af < 10 {
		return fmt.Sprintf("%.1f", f)
	} else if 10 <= af && af <= 1000 {
		return fmt.Sprintf("%.0f", f)
	}

	if af < 1 {
		var p = 8
		for math.Abs(f) < 1 && p >= 0 {
			f *= 1000
			p--
		}
		return FmtFloat(f) + Units[p]
	}

	var p = 7
	for math.Abs(f) > 1000 && p < 16 {
		f /= 1000
		p++
	}
	return FmtFloat(f) + Units[p]
}
307478
func (sf SizeFlag) String() string {
	// This happens when izZeroValue() from flag.go makes a zero
	// value from the type of a flag.
	if sf.v == nil {
		return "0"
	}
	v := *sf.v
	var suffix string
	const units = "kmgt"
	var c byte
	if v%1000 == 0 {
		for i := 0; v%1000 == 0 && i < len(units); i++ {
			c = units[i]
			v /= 1000
		}
		suffix = string(c)
	} else if v%1024 == 0 {
		for i := 0; v%1024 == 0 && i < len(units); i++ {
			c = units[i]
			v /= 1024
		}
		suffix = string(c) + "i"
	}
	return fmt.Sprintf("%d%s", v, suffix)
}
980282
func WriteFloat32(space []byte, val float32) []byte {
	abs := math.Abs(float64(val))
	fmt := byte('f')
	// Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
	if abs != 0 {
		if float32(abs) < 1e-6 || float32(abs) >= 1e21 {
			fmt = 'e'
		}
	}
	return append(space, strconv.FormatFloat(float64(val), fmt, -1, 32)...)
}
39362
func InRangeFloat32(value, left, right float32) bool {
	if left > right {
		left, right = right, left
	}
	return value >= left && value <= right
}
922673
func (db *RedisDB) Incrfloat(k string, delta float64) (float64, error) {
	db.master.Lock()
	defer db.master.Unlock()

	if db.exists(k) && db.t(k) != "string" {
		return 0, ErrWrongType
	}

	return db.stringIncrfloat(k, delta)
}
1374187
func (f Float) String() string {
	if !f.Valid {
		return nullString
	}

	return fmt.Sprintf("%1.3f", f.Float64)
}
202043
func fmtE(dst EncodingBuffer, neg bool, d decimalSlice, prec int, fmt byte) {
	// sign
	if neg {
		dst.WriteByte('-')
	}

	// first digit
	ch := byte('0')
	if d.nd != 0 {
		ch = d.d[0]
	}
	dst.WriteByte(ch)

	// .moredigits
	if prec > 0 {
		dst.WriteByte('.')
		i := 1
		m := min(d.nd, prec+1)
		if i < m {
			dst.Write(d.d[i:m])
			i = m
		}
		for i <= prec {
			dst.WriteByte('0')
			i++
		}
	}

	// e±
	dst.WriteByte(fmt)
	exp := d.dp - 1
	if d.nd == 0 { // special case: 0 has exponent 0
		exp = 0
	}
	if exp < 0 {
		ch = '-'
		exp = -exp
	} else {
		ch = '+'
	}
	dst.WriteByte(ch)

	// dd or ddd
	switch {
	case exp < 10:
		dst.WriteByte('0')
		dst.WriteByte(byte(exp) + '0')
	case exp < 100:
		dst.WriteByte(byte(exp/10) + '0')
		dst.WriteByte(byte(exp%10) + '0')
	default:
		dst.WriteByte(byte(exp/100) + '0')
		dst.WriteByte(byte(exp/10)%10 + '0')
		dst.WriteByte(byte(exp%10) + '0')
	}

	return
}
1154383
func floatToString(value float64, bitsize int) string {
	// TODO Fit to ECMA-262 9.8.1 specification
	if math.IsNaN(value) {
		return "NaN"
	} else if math.IsInf(value, 0) {
		if math.Signbit(value) {
			return "-Infinity"
		}
		return "Infinity"
	}
	exponent := math.Log10(math.Abs(value))
	if exponent >= 21 || exponent < -6 {
		return matchLeading0Exponent.ReplaceAllString(strconv.FormatFloat(value, 'g', -1, bitsize), "$1$2")
	}
	return strconv.FormatFloat(value, 'f', -1, bitsize)
}
398191
func (j *JSONPath) evalFloat(input []reflect.Value, node *FloatNode) ([]reflect.Value, error) {
	result := make([]reflect.Value, len(input))
	for i := range input {
		result[i] = reflect.ValueOf(node.Value)
	}
	return result, nil
}
383474
func (c Case) ShortString(length int) string {
	return fmt.Sprintf("%s%d [%s, %s]: %s(%s) = %s %s",
		c.Prefix, c.Prec, c.Trap, c.Mode, c.Op,
		join(c.Inputs, ", ", length), trunc(c.Output, length), c.Excep)
}
1255338
func SizeToString(s int64) string {
	v := float64(s)
	i := 0
	for ; i < len(units); i++ {
		if v < 1024. {
			break
		}
		v /= 1024.
	}
	if i == 0 {
		return fmt.Sprintf("%d%s", s, units[i])
	}
	if v >= 10 {
		return fmt.Sprintf("%.1f%s", v, units[i])
	}
	return fmt.Sprintf("%.2f%s", v, units[i])
}
792661
func (iter *Iterator) ReadBigFloat() (ret *big.Float) {
	str := iter.readNumberAsString()
	if iter.Error != nil && iter.Error != io.EOF {
		return nil
	}
	prec := 64
	if len(str) > prec {
		prec = len(str)
	}
	val, _, err := big.ParseFloat(str, 10, uint(prec), big.ToZero)
	if err != nil {
		iter.Error = err
		return nil
	}
	return val
}
940910
func (m *Miniredis) HIncrfloat(k, f string, delta float64) (float64, error) {
	return m.DB(m.selectedDB).HIncrfloat(k, f, delta)
}
779944
func fmtFieldString(vals []interface{}, ok bool) *string {
	if !ok {
		return nil
	}
	parts := []string{}
	// TODO: improve testing for this, i'm sure this will fail with more complex field expressions
	for _, v := range vals {
		switch v.(type) {
		case mss.Field:
			parts = append(parts, escapeSingleQuote(string(v.(mss.Field))))
		case string:
			parts = append(parts, escapeSingleQuote(v.(string)))
		}
	}
	r := "'" + strings.Join(parts, "") + "'"
	return &r
}
306748
func f(r0, r1, r2, r3 *uint32, k0, k1 uint32) {
	k0 ^= *r0
	k1 ^= *r1

	t := sbox4_4404[byte(k0)]
	t ^= sbox3_3033[byte(k0>>8)]
	t ^= sbox2_0222[byte(k0>>16)]
	t ^= sbox1_1110[byte(k0>>24)]
	*r3 ^= (t >> 8) | (t << (32 - 8))

	k0 = t
	k0 ^= sbox1_1110[byte(k1)]
	k0 ^= sbox4_4404[byte(k1>>8)]
	k0 ^= sbox3_3033[byte(k1>>16)]
	k0 ^= sbox2_0222[byte(k1>>24)]

	*r2 ^= k0
	*r3 ^= k0
}
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
}
1273046
func (v *Value) bytesToFloat() (float64, bool) {
	bytes, _ := v.ToBytes()
	i, err := strconv.ParseFloat(string(bytes), 64)
	return i, err == nil
}