views:

53

answers:

3
+2  Q: 

calculate midpoint

Why in the bisection method it is better to compute the midpoint c between a and b with

c = a + (b - a) / 2.

instead of the simpler:

c = (a + b) / 2.

all variables are floating points.

+2  A: 

it is to avoid any potential overflows / loss of precision in intermediate calculations.

tenfour
Overflow shouldn't be a problem with floating point types. Loss of precision might be.
Henk Holterman
thanks - updated
tenfour
+1  A: 

There is an interesting (old) blog post about this type of issue on Joshua Bloch's blog:

http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html

corriganjc
Good point but the tags say floating-point.
Henk Holterman
So they do. I missed that. Thanks for pointing it out. In the floating point case your comment is the most useful.
corriganjc