add division
This commit is contained in:
parent
c933c2a2c5
commit
1f6b61cee0
38
f.go
38
f.go
|
@ -69,18 +69,44 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens := strings.Split(strings.TrimSpace(input), " ")
|
tokens := strings.Split(strings.TrimSpace(input), " ")
|
||||||
if len(tokens) != 2 {
|
var err1, err2 error
|
||||||
fmt.Println("Please enter exactly two floats.")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
new_low, err1 := strconv.ParseFloat(tokens[0], 64)
|
var new_low, new_high float64
|
||||||
new_high, err2 := strconv.ParseFloat(tokens[1], 64)
|
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 {
|
if err1 != nil || err2 != nil {
|
||||||
fmt.Println("Invalid input. Please ensure you enter two floats.")
|
fmt.Println("Invalid input. Please ensure you enter two floats.")
|
||||||
continue
|
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
|
// Use the abstracted function for combining floats
|
||||||
old_low, old_high = combineBounds(old_low, old_high, new_low, new_high)
|
old_low, old_high = combineBounds(old_low, old_high, new_low, new_high)
|
||||||
fmt.Printf("=> %.1f %.1f\n", old_low, old_high)
|
fmt.Printf("=> %.1f %.1f\n", old_low, old_high)
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user