|
Boost Users : |
Subject: Re: [Boost-users] [Interval] Help debugging compiler optimization
From: Ilja Honkonen (ilja.honkonen_at_[hidden])
Date: 2018-03-08 08:49:04
Hello
> My (somewhat naive) view of compilers is that they can only do
> optimization that has no visible effects on the behavior of the program.
I wouldn't be surprised if ieee floating point is an exception to that,
especially with optimizations enabled.
> What I meant is:
> double v1 = 1.0/3.0;
> printf("%f", v1);
> double computation = v1 * 3;
> Then the print statement will show the user some value for v1 that fits
> in a double. So I would expect that it is then no longer free to treat
> v1 as exactly 1/3, because the use has already observed a different value.
I think in order to show the number to the user it would have to be
copied to memory or at least a regular register but further computation
could continue to use the more accurate floating point register. And the
compiler might still optimize the computation away and just show you the
result of printf(..., 1.0/3.0). I don't know if writing constexpr double
v1 = 1.0/3.0 would change anything, at least if particular optimizations
are enabled and/or disabled.
Ilja
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net