commit 2262d5b617c0092440fa41cbc84c969f34eb2665
parent b319e29be8570d8664478774b0f408caac950977
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Mon, 3 Jun 2024 08:45:33 +0200
add K/M/B/T to output
Diffstat:
| M | README.md | | | 2 | ++ |
| M | f.go | | | 40 | ++++++++++++++++++++++++++++++++++++++-- |
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git 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
@@ -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)
}
}