QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Bert22306 on March 01, 2021, 05:35:18 am
-
Surely, this trivial program should be giving the same result, for x, y, and z??
Screen _NewImage(120, 43, 0)
For i = 1 To 10
x = 15 * i / 3000
y = i / 3000 / 15
z = i / (3000 / 15)
Print x, y, z
Next i
End
Was going bonkers trying to debug something, and the problem came down to the above, when distilled to its basics. What am I forgetting? Thanks!
-
Forgetting basic math?
1 / 2 / 3 isn't the same as 3 * 1 / 2....
x = 15 * i / 3000
y = i / 3000 * 15
z = i / (3000 / 15)
-
Forgetting something, for sure. Best to be generous with parentheses. Thanks, Steve!
It was a case of, 1 / 2 / 3 is not the same as 1 / (2 / 3)
In fact, 1 / (2 / 3) is the same as 3 * 1 / 2.
That was my issue.