This is the mail archive of the
mailing list for the GCC project.
Re: Kahan's Floating Point Test
- To: <moshier at moshier dot ne dot mediaone dot net>, "Michael Price" <mprice at atl dot imco dot com>
- Subject: Re: Kahan's Floating Point Test
- From: "Tim Prince" <tprince at computer dot org>
- Date: Thu, 31 May 2001 08:24:29 -0700
- Cc: <gcc at gcc dot gnu dot org>
- References: <Pine.LNX.email@example.com>
----- Original Message -----
From: "Stephen L Moshier" <firstname.lastname@example.org>
To: "Michael Price" <email@example.com>
Sent: Wednesday, May 30, 2001 9:51 AM
Subject: Re: Kahan's Floating Point Test
> > Its annoying to have a program that heavily uses floating
> > point math to produce the same output on FreeBSD and Solaris but
> > different output on Linux.
> It's annoying to see this question come up repeatedly, too! Don't
> we have a FAQ paragraph about this?
> The floating point hardware on x86 is not IEEE compliant. You can
> come close by setting the rounding precision of the fpu to the desired
> working precision of the numbers. See /usr/include/fpu_control.h
> on linux for the functions or macros to do that.
> After setting the precision there will still be an occasional problem
> when the exponent goes outside the range of the desired precision.
> PARANOIA usually complains about a problem with tiny denormal numbers
> because of that. You have to ensure the result is written out from
> the fpu to memory in order to fix this problem. The float-store
> switch of GCC will force some, but not all, results to be written out.
> If you didn't already know this was a problem, the chances are that
> you will not be much affected by it. But you should (always anyway)
> avoid careless comparisons between floating point values.
One of the necessary modifications to Paranoia to make it work with
extended width register architectures (which go back at least 20 years
prior to x86) is to force storage to memory at strategic places. I don't
totally understand why Kahan didn't do this, as he was (AFAIK) an advocate
of such architectures and their incorporation into IEEE standards. As
Stephen points out, failing to do this, even after setting precision mode,
will produce inconsistencies in exponent range. I expect the same would
happen on some PowerPC architectures. -ffloat-store will not solve the
problem, as it will kick in where it is not wanted and sometimes not where
it is wanted.