O'Reilly logo

Java™ Number Cruncher: The Java Programmer's Guide to Numerical Computing by Ronald Mak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Summing Lists of Numbers

A typical assignment in Computer Programming 101 is to write a program that sums a list of numbers. If you add many numbers, say hundreds or thousands of them, and there are no overflows, then you might reasonably expect that the roundoff errors will cancel each other out, and the sum will be fairly accurate. What could possibly go wrong?

This chapter shows that even such a simple operation can go wrong if we're careless about floating-point arithmetic. Several summation problems will illustrate some of the typical pitfalls. We'll take an experimental approach by writing programs that try different summation techniques to find ones that either compensate for the roundoff errors or reduce the opportunities for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required