# Floating point differences between solaris and linux

John Yates jyates@netezza.com
Fri Dec 26 15:17:00 GMT 2003

```What Every Computer Scientist Should Know About Floating-Point Arithmetic:
http://www.esatechnology.com/library/math/floatingmath.pdf

IEEE double has a 53 bit precision.  Hence it can resolve
1 part in 2^53.  This comes out to a resolution of 1 part
in 9007199254740992.  Count them.  That's 16 decimal digits.
All of you answers match in the first 15 digits:

2666682129.57945

You are attempting to manipulate numbers specified to 29
digits.

Places where variations will creep in:

- conversion from text to binary
- rounding mode
- possible use of x86 80-bit floating point
- if product is performed at compile time does compiler
produce bit-for-bit identical results
- conversion from binary to text

/john

-----Original Message-----
From: Venkatesh Nagarajan [mailto:venkat@evafunds.com]
Sent: Thursday, December 25, 2003 6:20 PM
To: gcc-help@gcc.gnu.org
Subject: Floating point differences between solaris and linux

Hi

I am using Sun SPARC machine running Solaris 5.6 and an Intel Xeon
machine running 7.3 linux with GCC 2.96.113 compiler.
I am multiplying 2 doubles with a simple program and the answers are
different. What am I missing? Is this a difference in the compiler?
Architecture? Operating System?

Even Linux itself gives two different results with Optimization turned
on and off!!!

Thanks
Venkat

/******************* SOLARIS
************************************************/

SunOS evaadmin03 5.6 Generic_105181-35 sun4u sparc sun4u
#include <stdio.h>
int main() {

double a = 51859.435045995065593160688877;
double b = 51421.349407573121425230056047;
double c = a * b;

printf("%24.24f * %24.24f = %24.24f\n", a, b, c);

return 1;
}
evaadmin03:/usr/evahome/venkat/test 51 CC -o foo.solaris foo.C
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579454898834228515625000

/************************************ LINUX
*****************************************/

Linux evadevel07 2.4.20-20.7smp #1 SMP Mon Aug 18 14:46:14 EDT 2003 i686
unknown
evadevel07:/usr/evahome/venkat/test 28 g++ -o foo.linux foo.C
foo.linux*   foo.solaris*
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579455375671386718750000

/************************* LINUX differences with and without
optimization flag ***********************************/

evadevel07:/usr/evahome/venkat/test 38 g++ -o foo.linux foo.C