def sum = series.map(_.sum).foldLeft(0.0)(_+_)
Gah, no, stop. Remember, kids: everytime you use naive map-reduce for floating point arithmetic operations, God kills a kitten. def sum = series.map(_.sum).foldLeft(0.0)(_+_)
Gah, no, stop. Remember, kids: everytime you use naive map-reduce for floating point arithmetic operations, God kills a kitten.http://en.wikipedia.org/wiki/Floating_point#Accuracy_problem...
edit: You're write jfager. I didn't read the article I linked to very carefully. The article actually has an example algorithm, the Kahan sum, for reducing the error caused by summing floating point numbers in a loop!