gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] The killer heuristic


From: Evan Berggren Daniel
Subject: Re: [gnugo-devel] The killer heuristic
Date: Sat, 25 Jan 2003 22:43:19 -0500 (EST)

Ok, having stared at it some more...

I'm running on x86; gcc uses the standard x87 fp instructions, which use
an 80-bit fp register.  So, x / 3.0 gets calculated to 80-bit precision in
register, and then y gets loaded from memory, where it was stored to only
32-bit precision.  Thus, y gets moved to an 80-bit register where it has
some 0s added in the least significant bits, and the two are not strictly
equal.

On my computer, changing the if statement to
if (((float)(x / 3.0)) == y)
makes the program print the same.

Looking at the assembly produced, gcc adds a floating point store / load
when I have the cast in place, which serves to truncate to 32 bits, which
means the two are indeed equal.

One solution is to use -ffloat-store, which forces all variables to be
truncated properly.  However, the results of any floating point comparison
must be stored to a variable for this to have an effect.

Evan Daniel

On Sun, 26 Jan 2003, Arend Bayer wrote:

> Evan wrote:
>
> > Floating point rounding problems is an interesting thought...  is there a
> > way to compile things to do IEEE floating point instead of platform
> > dependent, to test this out?
>
> Well gcc has an option -mieee-fp but I doubt this works.
>
> Try the example program below. I consistently get "not equal" as result
> (also with -mieee-fp). When compiling this with -O2, the executable
> doesn't even contain the string "the same" anymore, as this branch gets
> optimized away.
>
> I don't know IEEE, so either this is IEEE-correct (which means that IEEE
> doesn't do what one (at least me) would naively expect it to do), or
> this should be considered a compiler bug.
>
> Arend
>
>
> #include <stdio.h>
> #include <unistd.h>
>
> int
> main()
> {
>       float x = 1.0;
>       float y = 1.0/3.0;
>
>       if (x / 3.0 == y)
>                       fprintf(stdout, "the same\n");
>       else
>                       fprintf(stdout, "not equal\n");
>       return 0;
> }
>
>
>
>
>
> _______________________________________________
> gnugo-devel mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/gnugo-devel
>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]