commit 1f6b61cee0c96cba4ce3b0aba81f7d99270488db
parent c933c2a2c5787875a34e4c542acd7956cd67fe02
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Fri, 10 May 2024 20:50:55 +0100
add division
Diffstat:
2 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/f.go b/f.go
@@ -69,18 +69,44 @@ func main() {
}
tokens := strings.Split(strings.TrimSpace(input), " ")
- if len(tokens) != 2 {
- fmt.Println("Please enter exactly two floats.")
- continue
- }
+ var err1, err2 error
- new_low, err1 := strconv.ParseFloat(tokens[0], 64)
- new_high, err2 := strconv.ParseFloat(tokens[1], 64)
- if err1 != nil || err2 != nil {
- fmt.Println("Invalid input. Please ensure you enter two floats.")
+ var new_low, new_high float64
+ switch len(tokens) {
+ case 0:
continue
- }
+ case 1:
+ continue
+ case 2:
+ new_low, err1 = strconv.ParseFloat(tokens[0], 64)
+ new_high, err2 = strconv.ParseFloat(tokens[1], 64)
+ if err1 != nil || err2 != nil {
+ fmt.Println("Invalid input. Please ensure you enter two floats.")
+ continue
+ }
+ case 3:
+ switch tokens[0] {
+ case "*":
+ new_low, err1 = strconv.ParseFloat(tokens[1], 64)
+ new_high, err2 = strconv.ParseFloat(tokens[2], 64)
+ if err1 != nil || err2 != nil {
+ fmt.Println("Invalid input. Please ensure you enter two floats.")
+ continue
+ }
+ case "/":
+ new_low, err1 = strconv.ParseFloat(tokens[1], 64)
+ new_high, err2 = strconv.ParseFloat(tokens[2], 64)
+ if err1 != nil || err2 != nil {
+ fmt.Println("Invalid input. Please ensure you enter two floats.")
+ continue
+ }
+ tmp_low := new_low
+ new_low = 1.0 / new_high
+ new_high = 1.0 / tmp_low
+ default:
+ }
+ }
// Use the abstracted function for combining floats
old_low, old_high = combineBounds(old_low, old_high, new_low, new_high)
fmt.Printf("=> %.1f %.1f\n", old_low, old_high)
diff --git a/pianotuners.f b/pianotuners.f
@@ -1,9 +0,0 @@
-Please enter exactly two floats.
-4000000 12000000
-=> 4000000.0 12000000.0
-0.005 0.01
-=> 25587.7 93795.1
-1/365 1/365
-Invalid input. Please ensure you enter two floats.
-1 1
-=> 25587.7 93795.1