Is the following equation always true?
x / 3 + y /3 + z / 3 = (x + y + z) / 3
I hope this is not too simple of a question. Every example I can think of, this equation is true. However, in a program I am writing, it appears that the left side of it works but not the right side. So I am trying to figure out if I just got lucky or I am out of my mind.
As mathematical equation of real numbers, it is always correct, due to the distributive law: $$x/3 + y/3 + z/3 = \tfrac13 x+\tfrac13 y+\tfrac13 z = \tfrac13(x+y+z) = (x+y+z)/3$$
However note that floating point operations on the computer only approximate the operations on real numbers; especially a division by three will in general not be exact on a floating point number. It may happen that rounding errors will work out OK for one of the expressions, but not for the other one, or it may happen that one expression overflows (which just means, an intermediate result is too large to be represented in the floating point format of the computer), while the other one doesn't.