title: In which order should floats be added to get the most precise result?
body: <p>This was a question I was asked at my recent interview and I want to know <em>(I don't actually remember the theory of the numerical analysis, so please help me :)</em></p>
  
  <p>If we have some function, which accumulates floating-point numbers:</p>
  
  <pre><code>std::accumulate(v.begin(), v.end(), 0.0);
  </code></pre>
  
  <p><code>v</code> is a <code>std::vector&lt;float&gt;</code>, for example.</p>
  
  <ul>
  <li><p><strong>Would it be better to sort these numbers before accumulating them?</strong></p></li>
  <li><p><strong>Which order would give the most precise answer?</strong></p></li>
  </ul>
  
  <p>I suspect that <strong>sorting</strong> the numbers in ascending order would actually make the numerical error <strong>less</strong>, but unfortunately I can't prove it myself.</p>
  
  <p><em>P.S. I do realize this probably has nothing to do with real world programming, just being curious.</em></p>