
Would it help to use
constexpr double v1 and constexpr computation,
to see what the compiler can compute at compile-time
and to use a better print method
std::cout.precision(std::numeric_limits<double>::max_digits10);
std::cout << v1 << “ “ << computation << std::endl;
to see the ‘true’ results of both your doubles?
godbolt.org may also help you see what assembler is produced.
Paul
---
Paul A. Bristow
Prizet Farmhouse
Kendal UK LA8 8AB
+44 (0) 1539 561830
From: Boost-users [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Tim van Erven via Boost-users
Sent: 08 March 2018 08:36
To: Mário Costa; boost-users@lists.boost.org
Cc: Tim van Erven
Subject: Re: [Boost-users] [Interval] Help debugging compiler optimization
Hi Mário,
My (somewhat naive) view of compilers is that they can only do optimization that has no visible effects on the behavior of the program.
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.
Best,
TIm
On 07/03/2018 18:43, Mário Costa wrote:
I don't really understand what you mean.
lets say you have
double v1 = 1.0/3.0;
double computation = v1 * 3;
Using, O2, the compiler might resolve, by performing expression analisys at compile time, that you have always a constant value of 1/3 * 3 = 1.
Now using O0, it might not optimize, and compute the value at runtime (just as an example).
Because 1/3 does not fit into any number of bits without lossing precision (unless you'd be using some symbolic library), multiplying v1 * 3, will result in a value diferent from 1, that will be the rule.
Another issue Degski mentions, its the error propagation associated with the order the expressions are evaluated/executed ...
On Wed, Mar 7, 2018 at 5:09 PM, Tim van Erven via Boost-users