diff --git a/README.md b/README.md index 9c43cb1..bce85c0 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ function f(){ } ``` +Note that these sed commands are just hacks, and won't parse e.g., `3.5K` correctly—it will just substitute for 3.5000 + ## Tips & tricks Conceptually clearer to have all the multiplications first and then all the divisions diff --git a/f.go b/f.go index 9afddde..6287fdf 100644 --- a/f.go +++ b/f.go @@ -40,6 +40,42 @@ func combineBounds(old_low, old_high, new_low, new_high float64) (float64, float return logParamsToBounds(logmean_product, logstd_product) } +func prettyPrintDist(low float64, high float64) { + // fmt.Printf("=> %.1f %.1f\n", low, high) + fmt.Printf("=> ") + switch { + case math.Abs(low) >= 1_000_000_000_000: + fmt.Printf("%.1fT", low/1_000_000_000_000) + case math.Abs(low) >= 1_000_000_000: + fmt.Printf("%.1fB", low/1_000_000_000) + case math.Abs(low) >= 1_000_000: + fmt.Printf("%.1fM", low/1_000_000) + case math.Abs(low) >= 1_000: + fmt.Printf("%.1fK", low/1_000) + case math.Abs(low) >= 1_000: + fmt.Printf("%.1fK", low/1_000) + default: + fmt.Printf("%.1f", low) + } + fmt.Printf(" ") + switch { + case math.Abs(high) >= 1_000_000_000_000: + fmt.Printf("%.1fT", high/1_000_000_000_000) + case math.Abs(high) >= 1_000_000_000: + fmt.Printf("%.1fB", high/1_000_000_000) + case math.Abs(high) >= 1_000_000: + fmt.Printf("%.1fM", high/1_000_000) + case math.Abs(high) >= 1_000: + fmt.Printf("%.1fK", high/1_000) + case math.Abs(high) >= 1_000: + fmt.Printf("%.1fK", high/1_000) + default: + fmt.Printf("%.1f", high) + } + fmt.Printf("\n") + // fmt.Printf("=> %.1f %.1f\n", low, high) +} + func main() { reader := bufio.NewReader(os.Stdin) @@ -79,7 +115,7 @@ InitialForLoop: } break } - fmt.Printf("=> %.1f %.1f\n", old_low, old_high) + prettyPrintDist(old_low, old_high) error_msg_cont := "Valid inputs: 2 || * 2 || / 2 || 2 20 || * 2 20 || / 2 20 || i || e" EventForLoop: @@ -189,6 +225,6 @@ EventForLoop: } old_low, old_high = combineBounds(old_low, old_high, new_low, new_high) - fmt.Printf("=> %.1f %.1f\n", old_low, old_high) + prettyPrintDist(old_low, old_high) } }