4 ms·
In a perfect world, a compiler would optimize this code to be equivalent to summing in a simple loop, at least if series were a projection or had a non-strict m
by sreque 17y ago
In a perfect world, a compiler would optimize this code to be equivalent to summing in a simple loop, at least if series were a projection or had a non-strict map function. Whether scalac and the JVM can work together to do this right now or not is beyond my knowledge. Hopefully specialization in Scala 2.8 will at least get the JVM one major step closer.
- jfager 17y agoSumming floating point numbers in a simple loop is just as bad. It's not an issue of efficiency, it's an issue of accuracy.
- sreque 17y agoI guess I've been causing the death of kittens for a while then. I couldn't, however, deduce from your wikipedia link or from a quick google search what the correct way of adding floating point numbers should be, though. Even the MS compiler guys at http://msdn.microsoft.com/en-us/library/aa289157%28VS.71%29.aspx http://msdn.microsoft.com/en-us/library/aa289157%28VS.71%29.... are writing code snippets that sum floating point numbers in a loop. 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!
- jfager 17y agoThe whole point of the article you linked to is how to avoid summing floating point numbers in a simple loop.