Incorrect runtime behavior involving comparison
Steve
moshier@dsp.sls.com
Mon Jan 10 18:31:00 GMT 2000
> bool t1 = z1.priority() > z2.priority();
> bool t2 = z2.priority() > z1.priority();
This fails on i386 because of the so-called extra-precise fpu register
effect. It is a feature, not a bug.
If you look at the generated assembly language
call priority__4zone
addl $16,%esp
fstpl -40(%ebp)
addl $-12,%esp
leal -8(%ebp),%eax
pushl %eax
call priority__4zone
addl $16,%esp
fcompl -40(%ebp)
you see that one result is stored out to memory and gets rounded off
from the extended register precision to double precision. The
other result is not stored; it remains in the fpu register as an
extra-precise value during the compare.
The program succeeds if you set the i386 math coprocessor to double
precision mode. Some systems, such as Microsoft Windows, do that by
default, but in doing so they throw away the extended precision long
double data type.
More information about the Gcc-bugs
mailing list