tweak parsing code.
This commit is contained in:
parent
4b21612d55
commit
6c98249e57
2
fermi.go
2
fermi.go
|
@ -186,6 +186,8 @@ func prettyPrintStats(dist Dist) {
|
|||
})
|
||||
print_ci := func(ci float64, prefix string) {
|
||||
x := sorted_xs[int(math.Round(float64(n)*ci))]
|
||||
fmt.Printf("%s", prefix)
|
||||
// pretty.PrettyPrintFloat(x)
|
||||
fmt.Printf("%s%f\n", prefix, x)
|
||||
}
|
||||
print_ci(0.01, "ci 1%: ")
|
||||
|
|
|
@ -52,14 +52,6 @@ func PrettyPrint2Floats(low float64, high float64) {
|
|||
PrettyPrintFloat(high)
|
||||
}
|
||||
|
||||
func multiplyOrPassThroughError(a float64, b float64, err error) (float64, error) {
|
||||
if err != nil {
|
||||
return b, err
|
||||
} else {
|
||||
return a * b, nil
|
||||
}
|
||||
}
|
||||
|
||||
func ParseFloat(word string) (float64, error) {
|
||||
// l = len(word) // assuming no UTF stuff
|
||||
switch len(word) {
|
||||
|
@ -71,19 +63,23 @@ func ParseFloat(word string) (float64, error) {
|
|||
|
||||
n := len(word) - 1
|
||||
f, err := strconv.ParseFloat(word[:n], 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
multiplier := 1.0
|
||||
switch word[n] {
|
||||
case '%':
|
||||
return multiplyOrPassThroughError(0.01, f, err)
|
||||
multiplier = 0.01
|
||||
case 'K':
|
||||
return multiplyOrPassThroughError(1_000, f, err)
|
||||
multiplier = 1_000
|
||||
case 'M':
|
||||
return multiplyOrPassThroughError(1_000_000, f, err)
|
||||
multiplier = 1_000_000
|
||||
case 'B':
|
||||
return multiplyOrPassThroughError(1_000_000_000, f, err)
|
||||
multiplier = 1_000_000
|
||||
case 'T':
|
||||
return multiplyOrPassThroughError(1_000_000_000_000, f, err)
|
||||
multiplier = 1_000_000
|
||||
default:
|
||||
return strconv.ParseFloat(word, 64)
|
||||
multiplier = 1.0
|
||||
}
|
||||
|
||||
return f * multiplier, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user