What's a good way to add a large number of small floats together?

Posted by splicer on Stack Overflow See other posts from Stack Overflow or by splicer
Published on 2010-03-16T16:49:25Z Indexed on 2010/03/16 16:51 UTC
Read the original article Hit count: 189

Say you have 100000000 32-bit floating point values in an array, and each of these floats has a value between 0.0 and 1.0. If you tried to sum them all up like this

result = 0.0;
for (i = 0; i < 100000000; i++) {
    result += array[i];
}

you'd run into problems as result gets much larger than 1.0.

So what are some of the ways to more accurately perform the summation?

© Stack Overflow or respective owner

Related posts about floating-point

Related posts about float