title: What's the best midpoint formula for floating point numbers?
body: <p>The first formula</p>
  
  <pre><code>m = (a + b) / 2
  </code></pre>
  
  <p>is simple, but has a great risk of overflow. Besides, <em>Numerical Analysis, 9th Edition</em> by Burden and Faires points out that</p>
  
  <blockquote>
    <p>when b - a is near the maximum precision of the machine, it is possible for (a + b) / 2 to return a midpoint the is not even in the interval [a, b].</p>
  </blockquote>
  
  <p>though no further explanation is provided.</p>
  
  <p>The second one</p>
  
  <pre><code>m = a + (b - a) / 2
  </code></pre>
  
  <p>is also correct, with a smaller chance of overflow. But for floating numbers, nearly equal values of a and b may lead to a loss of significance. </p>
  
  <p>So, which formula is better in practice? Also, an explanation for the quote statement will be appreciated.</p>