On 20.05.2016 14:34, Johan Engelen wrote:
On Thursday, 19 May 2016 at 18:22:48 UTC, Timon Gehr wrote:
dmd -run kahanDemo.d
1000000000000000.000000
1000000100000000.000000
1000000000000000.000000
dmd -m32 -O -run kahanDemo.d
1000000000000000.000000
1000000000000000.000000
1000000000000000.000000
Better?
Ignore if you think it's not relevant.
I am a bit lost in this thread. I thought this was about floating point
CTFE,
Yes, this is how it started out. :)
At some point, I made the comment that the compiler should never be
allowed to use a higher precision than the one specified, which
broadened the scope of the discussion somewhat. But the kinds of
problems caused by using higher precision than requested can be similar
for CTFE and runtime.
but I think what you are seeing here (in the 2nd case) is the DMD
optimizer allowing reassociation of fp expressions?
I don't believe it does (Walter knows /very/ well that a+(b+c) is not
the same as (a+b)+c), but I have not looked at the assembly output. The
result becomes wrong when 80 bit precision is used behind the scenes for
some (but not all) of the computation, so this could be the explanation.
LDC does not allow
that (per default) and produces the 1000000100000000.000000 result also
with optimization on.
-Johan
Thanks!