This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Serious bug


Richard Hadsell wrote:
> 
> Kamil Iskra wrote:
> >
> > Not to me. I was taught NEVER to use == or != with floating point, because
> > they simply don't make sense.

I agree.

> 
> I don't want to replace (x == 0.) by (x < 0. ? (x > -DBL_MIN) : (x <
> DBL_MIN)) for the simple cases (e.g., I assigned 0. to x earlier, did
> some other stuff which may have altered x, and now I want to see if x
> was altered).  I want the compiler to take care of that for me.  My
> experience says that most compilers do.  Don't bother telling me my
> expectations are too high.

I use abs(x) < epsilon where epsilon is a constant set to 1e-9.  This
value is
good enough for our purposes.

Your expectations are too high.  Suppose I have the following code:

for(i = 0, d = 0.0; i != 16777216; ++i, d += .1)
	;
for(i = 16777216; i != 0; --i, d -= .1)
	;

IIRC, .1 will never be represented exactly in IEEE format.  Therefore,
each floating point addition and subtraction will carry some error.  How
should the compiler account for such errors?  What about more
complicated situations?

Noel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]