[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Compiler bugs [ Was: (yet another) Infernal compiler error ]



Martin Kahlert <martin.kahlert@mchp.siemens.de> writes:

> Quoting Goswin Brederlow (goswin.brederlow@student.uni-tuebingen.de):
> > I have a programm that has several strange bugs, depending on options
> > and compiler versions used. I'm still trying to sepperate them and
> > make small test cases, but I think something is seriously wrong. The
> > code looks as follows (with a lot other stuff around).
> > 
#include <cmath>
> > double a,b;
> > 
> > a = angle();
> > if (abs(a - b) > 1E-10) {
> > 	cout << abs(a-b) << endl;
> > }
> > 
> > The output is something like
> > 
> > 1.358376E-15
> > 
> > which isn't greater than 1E-10 by no means. A gets calculated just
> > before the if, so I would guess that some pipelining is wrong.
> abs is a function, which only works for integers and returns an int.
> (man 3 abs). You want to use fabs:

Actually I don't. I forgot to say that its c++ code and I include
"cmath", so abs is overloaded for doubles.

Anyway, it wouldn't make a difference. abs(a-b) gives a very small
number as the cout shows, which is not greater than 1E-10, but the
cout is still executed.

MfG,
	Goswin


Reply to: