Revert "tweak parsing code."

This reverts commit 6c98249e57.
This commit is contained in:
NunoSempere 2024-11-20 11:20:21 +00:00
parent 6c98249e57
commit ae1e1bbe97
2 changed files with 15 additions and 13 deletions

View File

@ -186,8 +186,6 @@ 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%: ")

View File

@ -52,6 +52,14 @@ 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) {
@ -63,23 +71,19 @@ 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 '%':
multiplier = 0.01
return multiplyOrPassThroughError(0.01, f, err)
case 'K':
multiplier = 1_000
return multiplyOrPassThroughError(1_000, f, err)
case 'M':
multiplier = 1_000_000
return multiplyOrPassThroughError(1_000_000, f, err)
case 'B':
multiplier = 1_000_000
return multiplyOrPassThroughError(1_000_000_000, f, err)
case 'T':
multiplier = 1_000_000
return multiplyOrPassThroughError(1_000_000_000_000, f, err)
default:
multiplier = 1.0
return strconv.ParseFloat(word, 64)
}
return f * multiplier, nil
}