Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.compilers > #62

Re: GCC/G++ compiler: Error goes away when run through debugger

From glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups comp.compilers
Subject Re: GCC/G++ compiler: Error goes away when run through debugger
Date 2011-03-29 18:47 +0000
Organization A noiseless patient Spider
Message-ID <11-03-062@comp.compilers> (permalink)
References <11-03-054@comp.compilers> <11-03-059@comp.compilers>

Show all headers | View raw


Torben Fgidius Mogensen <torbenm@diku.dk> wrote:

(snip)
> The moral is, of course, that I should not have used equality tests
> for FP numbers, but instead used an "within epsilon" test.  In
> general, you should not expect FP calculations to give exactly the
> same result after optimisation in C or C++, as the order of evaluation
> is not fully specified and because the compiler might optimise a
> multiplication followed by an addition to a multiply-and-add, which
> can change rounding behaviour.

In addition, many compilers do constant expression evaluation
sufficiently different from run-time evaluation that comparisons may
fail for that reason.  There are even some that use special libraries
to evaluate constant expressions to very high precision when there is
no need for such precision.

With x87 floating point, intermediate results are kept with 64
significant bits, unless the value is stored.  Sometimes even though
as written the value is stored, the optimizer will keep it in a
register.

Fortran, unlike C89 (but I believe like C99) requires parentheses to
be respected regarding evaluation order, even with mathematically
equivalent expressions.  Other than that, there are many other
optimizations that can change the value of floating point expressions,
and that are legal.

-- glen

Back to comp.compilers | Previous | Next | Find similar


Thread

Re: GCC/G++ compiler: Error goes away when run through debugger glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2011-03-29 18:47 +0000

csiph-web