This is the mail archive of the 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]
Other format: [Raw text]

Re: Spurious differences between 32 and 64 bit mode numeric results

Andreas Svrcek-Seiler <> writes:

> Dear developers,
> I've just tested a numerically intensive program.
> I compiled it on Fedora core 2 x86_64  using a self compiled 
> gcc/g++ 3.4.0 (and 3.3.3 as it comes with Fedora).
> Result for both compilers: The program, takes more steps until the main
> iteration converges when compiled in 64 bit mode when compared in
> 32 bit mode.
> Since I know the program to converge faster (albeit at doubled 
> and potentially prohibitive memory requirements) when running with doubles 
> instead of floats, this seems to indicate that in 64 bit mode, some
> numerical calculations are less accurate, at least when performed with 
> floats. Btw, there's no fancy math involved,the 
> time consuming inner loop is all adds and mults.

The problem is that x86 does the float and double calculation with
extra bits - the x87 fpu uses long double internally.  As long as the
value is in the fpu it is calculated with 80 bits and rounded

You should get the same results if you add -ffloat-store for x86.

Compare this also:
#include <stdio.h>
main (void)
  float b, c;

  b = 1 / 3.0f;
  c = b * 3.0f - 1.0f;
  printf ("c: %.20f\n", c);
  return 0;

Compiling and executing this program on an Linux/AMD64 system gives
different results between 32-bit x86 and 64-bit binaries:

$ gcc t.c -m32 -o t32
$ gcc t.c -o t64
$ ./t32 
c: 0.00000002980232238770
$ ./t64
c: 0.00000000000000000000

Btw. you will get the same results on most other CPUS as on AMD64, x86
is the odd one here.

Note that this has nothing todo with GCC development itself and
therefore is off-topic for this list,

 Andreas Jaeger,,
  SUSE Linux AG, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

Attachment: pgp00000.pgp
Description: PGP signature

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