]> git.lizzy.rs Git - rust.git/commit
auto merge of #10927 : g3xzh/rust/sum_bugfix, r=huonw
authorbors <bors@rust-lang.org>
Thu, 19 Dec 2013 02:41:35 +0000 (18:41 -0800)
committerbors <bors@rust-lang.org>
Thu, 19 Dec 2013 02:41:35 +0000 (18:41 -0800)
commitb4ed6f969592595cf821bf9f72b015185a56b4f0
tree2fc477e92708e68fca4d3555c70bb1c5efcfbc38
parent3c2c13bae4783c808f6640286d41cba6d9394dd9
parent05395cba88580db10455952706cd8ae292fdbbe7
auto merge of #10927 : g3xzh/rust/sum_bugfix, r=huonw

`[1e20, 1.0, -1e20].sum()` returns `0.0`. This happens because during
the summation, `1.0` is too small relative to `1e20`, making it
negligible.

I have tried Kahan summation but it hasn't fixed the problem.
Therefore, I've used Python's `fsum()` implementation.
For more details, read:
www.cs.cmu.edu/~quake-papers/robust-arithmetic.ps
https://github.com/mozilla/rust/issues/10851

Python's fsum (msum)
http://code.activestate.com/recipes/393090/

@huonw, your feedback is more than welcome.
It looks unpolished; Do you have suggestions how to make it more beautiful and elegant?

Thanks in advance,
src/libextra/stats.rs