This is the mail archive of the gcc-bugs@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: Floating point rounding errors in current egcs(?!)


Craig Jones wrote:

> Bear with me...

[ Because you didn't send in a complete source showing the problem,
  I have to guess below - so bear with me :-) ]

> My primary machine is a linux box (P2-350 with Redhat 6.0 and
> egcs-2.91.66).
> The second machine is a P90 and my program compiled under MSDev 5.0 /
> Win95.
> The third machine is a Sparc20 running Solaris 5.6 and the egcs-2.91.66
> as the compiler.

> The second and third machine produce _exactly_ the same values.  The
> first machine produces slightly different values than the other two
> machines.  I am guessing that it is due to round off error, but why?
> All variables are double precision.

This information might just be sufficient to derive what's going on. 
You get the same results using the Windows compiler on an ix86 processor
and egcs on a SPARC CPU.  This indicates that the Windows compiler is
able to keep the ix86 from using the 80-bit (64-bit mantissa) precision
of intermediate values in registers on the Intel architecture.  It can
use two approaches for this:

1. Store all intermediate values in computations in memory and retrieve
   them from there.  This will truncate all intermediate values to 64-
   bit (53-bit mantissa) precision - the same as what the SPARC CPU uses

2. Set the "precision" mode of the Intel CPU into 64-bit (53-bit
   mantissa) precision.  This will force the processor to evaluate all
   arithmetic in "double" precision, regardless of whether the value
   lives in a register or in memory.

Solution (2.) can be mimicked with egcs by using a special function call
available in glibc.  Please read the glibc documentation accompanying
your RedHat 6.0 distribution.

Hope this helps,

-- 
Toon Moene (toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
GNU Fortran: http://world.std.com/~burley/g77.html


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