...
1 package util
2
3 import (
4 "fmt"
5 "math"
6 "strconv"
7 )
8
9
10
11 func ParseStringToFloat(s string) (float64, error) {
12 switch s {
13 case "inf":
14 return math.Inf(1), nil
15 case "-inf":
16 return math.Inf(-1), nil
17 case "nan", "-nan":
18 return math.NaN(), nil
19 }
20 return strconv.ParseFloat(s, 64)
21 }
22
23
24 func MustParseFloat(s string) float64 {
25 f, err := ParseStringToFloat(s)
26 if err != nil {
27 panic(fmt.Sprintf("redis: failed to parse float %q: %v", s, err))
28 }
29 return f
30 }
31
View as plain text