27 Mar
2017
27 Mar
'17
12:43 p.m.
At 11:30 AM 3/27/2017, Mike Speciner wrote:
(double)(x+y) == (double)x+(double)y;
is false for some values of x and y as long as x and y are not already doubles (and even if they are if any are or result in NaN).
Isn't it true if x and y are 32 bit ints? You'll never exceed the number of fraction bits of a double. The point is, if you have a calculation that is being gradually promoted from ints to doubles, you don't need to worry about the mixed parts of the calculation. You can just let the compiler do what it will and convert the ints when and where it feels like. It's the reason languages like javascript, which don't even have an integer type, get away with it.