Not sure what you are asking... are you questioning why this...
Is not identical to this?
Well, one possibiliity, is that the addition is done in a different order. So, depending on what the types are, it is possible for the result to be different. For example, what if they were all string types?
And even if we ignore Strings, double / float (in general: floating point) addition may do some rounding between calls. Therefore, a + b + c may be slightly different from a + c + b.
Rob Prime wrote:And even if we ignore Strings, double / float (in general: floating point) addition may do some rounding between calls. Therefore, a + b + c may be slightly different from a + c + b.
There is no such type of problem of rounding because " + " operator will do automatic widening according to its operands and convert both in the bigger one.
There is no such type of problem of rounding because " + " operator will do automatic widening according to its operands and convert both in the bigger one.
I believe Rob was referring to precision lost, due to rounding during the operation... try this...
Believe it or not, this will produce slightly different results.... and the reason is because different interim values have different amount of precision lost.
There is no such type of problem of rounding because " + " operator will do automatic widening according to its operands and convert both in the bigger one.
I believe Rob was referring to precision lost, due to rounding during the operation...
Rob Prime wrote:
And that last example is quite terrifying.
Numerical computing weenies such as myself know all about this kind of thing. Read about the Kahan summation algorithm to see the lengths that you sometimes need to go to!
I knew there could be rounding errors, but all examples I've seen so far have had errors of less than 0.0001.
It makes sense that in your example the value of c is virtually ignored, but I would never have thought up such an example.
Believe it or not, this will produce slightly different results.... and the reason is because different interim values have different amount of precision lost.
Believe it or not, this will produce slightly different results.... and the reason is because different interim values have different amount of precision lost.
Henry
what is precision lost
Refer to the post Ernest made with a link to the Kahan algorithm. It explains a lot.
hmm, the problem seems like it would be more basic than that.. The question just looks to me like it owuld be something simpler. Have you learned about what Ernest linked to? or is this a more basic java question?
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
a bit of art, as a gift, the permaculture playing cards