diff --git a/fermi.go b/fermi.go index 64f98ab..8a4e4fc 100644 --- a/fermi.go +++ b/fermi.go @@ -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%: ") diff --git a/pretty/pretty.go b/pretty/pretty.go index d092ad7..3e6eb79 100644 --- a/pretty/pretty.go +++ b/pretty/pretty.go @@ -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 + }