Hacker News new | ask | show | jobs
by bonzini 2185 days ago
Stuff like Kahan summation breaks horribly with -ffast-math, because if you assume that sum is associative the error term, which is ((s+x)-s)-x, simplifies to zero.

https://en.m.wikipedia.org/wiki/Kahan_summation_algorithm

2 comments

Yeah, that's the obvious counterexample, but that's why I said "more often than not". The statement I was questioning was that fast-math is "normally not more correct."
That's where you dust off volatile.
Sadly true. That's the only portable way I found to implement something akind to a Kahan sum so that no compiler / flag would destroy it.