Category Archives: Mathematics

My computer can’t add (part 2)

In My computer can’t add (part 1) introduced Kahan summation and showed how it helps to improve the accuracy of summing up a large number of floating point values.  Kahan’s algorithm is fine for this task, but what happens when one tries combining the result of two sums?  What if you need to multiply the compensated sum by some value?  This led to a number of searches on Google and online publishers that turned up relatively little.  What I did eventually find led me to the double-double precision and double-single precision libraries written in Fortran.  Currently, they reside at http://crd-legacy.lbl.gov/~dhbailey/mpdist/.  I am going to focus on the addition operators again, but the Fortran code shows how to handle multiplication, transcendental functions and pretty much everything else you could want. Continue reading

My computer can’t add (part 1)

I recently asked some of my colleagues a question relating to the Kahan compensated summation algorithm and was greeted with blank stares and the question “What’s that?”  This caught me off guard as I had known about it for a few years.  I can’t remember how I found out about it, but I think that journey started with a single tutorial question in 2nd year applied maths and when I read “What every computer scientist should know about floating-point arithmetic” by David Goldberg.  I’ll start this off with why this algorithm matters, then what it actually is. Continue reading