I'll assume that this is just an example of the equation and not the actual code you are trying to compile.
This is not a compiler error. It is a characteristic of integer arithmetic. Your code at the top has a slightly different expression.
(a - b)/c
assume
a = 20
b = 9
c = 10
a - b is equal to 11
11/ 10 is equal to 1. Remember that you are working with integers
(a/c) + (b/c) with the same values is
20/10 is equal to 2
9/10 is equal to 0
2 - 0 is equal to 2
This sort of problem will happen with floats as well because floats are just approximations of real numbers. It is considered an error to test for equality in floats. If you aren't testing for equality than I recommend that you do your math in floats and only convert the end result into integers at the end.
Quote:
Originally Posted by Mr.Macdonald
I found a compiler error.
based upon my motors behavior, I believe that upon compilation I get a math error.
if (a+b)/c = d
and (a/c) + (b/c) = e
then d != e
|