Java Number Cruncher: The Java Programmer's Guide to Numerical Computing By Ronald Mak
Table of Contents
Chapter 4. Summing Lists of Numbers
4.6 Summation Summary
We can sum up, so to speak, the lessons of this chapter:
When summing lists of numbers with the same sign, add them in the sorted order of the smallest magnitude to the largest.
Avoid magnitude errors that occur whenever the differences between the binary exponents of the addends exceed 24 for float and 53 for double. The Kahan Summation Algorithm works well despite magnitude errors.
When summing lists of numbers with mixed signs, avoid cancellation errors by subtotaling the positive and negative numbers separately.
Double-precision arithmetic is not a cure-all.
Sometimes we may have to try several summation algorithms before we find one that works.
The best strategy of all is to gain some insight into the nature of the problem.