accuracy

Jul 2010
15
0
m1 = a + (b-a)/2

m2 = (a+b)/2

why is it that m2's result is more accurate than m1's result ?
 

CaptainBlack

MHF Hall of Fame
Nov 2005
14,975
5,273
erehwon
m1 = a + (b-a)/2

m2 = (a+b)/2

why is it that m2's result is more accurate than m1's result ?
Is that the complete question, is there not some contextual information you have omitted?

(especially as in any compiled language the optimiser will change the rhs of the first into am form identical to the rhs of the second)

CB
 
Jul 2010
15
0
normal floating point arithmetic of a pc applies in this case. I have seen many bisection algorithms do it like m2. Why does m1 produce a lower accurate result?
 

CaptainBlack

MHF Hall of Fame
Nov 2005
14,975
5,273
erehwon
normal floating point arithmetic of a pc applies in this case. I have seen many bisection algorithms do it like m2. Why does m1 produce a lower accurate result?
The more operations the larger the rounding errors will become, similarly one should avoid subtracting near equal quantities. All of which makes m1 probably better than m2.

CB