diff --git a/f.go b/f.go index adfeff9..d44a58e 100644 --- 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 deleted file mode 100644 index 5bddb95..0000000 --- a/pianotuners.f +++ /dev/null @@ -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