public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Floating point differences between solaris and linux
@ 2003-12-25 23:19 Venkatesh Nagarajan
  0 siblings, 0 replies; 2+ messages in thread
From: Venkatesh Nagarajan @ 2003-12-25 23:19 UTC (permalink / raw)
  To: gcc-help

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
************************************************/

evaadmin03:/usr/evahome/venkat/test 49 uname -a
SunOS evaadmin03 5.6 Generic_105181-35 sun4u sparc sun4u
evaadmin03:/usr/evahome/venkat/test 50 cat foo.C 
#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
evaadmin03:/usr/evahome/venkat/test 52 ./foo.solaris
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579454898834228515625000
evaadmin03:/usr/evahome/venkat/test 53

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

evadevel07:/usr/evahome/venkat/test 27 uname -a
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
evadevel07:/usr/evahome/venkat/test 29 ./foo.
foo.linux*   foo.solaris* 
evadevel07:/usr/evahome/venkat/test 29 ./foo.linux 
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579455375671386718750000
evadevel07:/usr/evahome/venkat/test 30


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

evadevel07:/usr/evahome/venkat/test 38 g++ -o foo.linux foo.C
evadevel07:/usr/evahome/venkat/test 39 ./foo.linux
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579455375671386718750000
evadevel07:/usr/evahome/venkat/test 40 g++ -O -o foo.linux foo.C
evadevel07:/usr/evahome/venkat/test 41 ./foo.linux
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579454898834228515625000
evadevel07:/usr/evahome/venkat/test 42

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: Floating point differences between solaris and linux
@ 2003-12-26 15:17 John Yates
  0 siblings, 0 replies; 2+ messages in thread
From: John Yates @ 2003-12-26 15:17 UTC (permalink / raw)
  To: Venkatesh Nagarajan, gcc-help

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
************************************************/

evaadmin03:/usr/evahome/venkat/test 49 uname -a
SunOS evaadmin03 5.6 Generic_105181-35 sun4u sparc sun4u
evaadmin03:/usr/evahome/venkat/test 50 cat foo.C 
#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
evaadmin03:/usr/evahome/venkat/test 52 ./foo.solaris
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579454898834228515625000
evaadmin03:/usr/evahome/venkat/test 53

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

evadevel07:/usr/evahome/venkat/test 27 uname -a
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
evadevel07:/usr/evahome/venkat/test 29 ./foo.
foo.linux*   foo.solaris* 
evadevel07:/usr/evahome/venkat/test 29 ./foo.linux 
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579455375671386718750000
evadevel07:/usr/evahome/venkat/test 30


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

evadevel07:/usr/evahome/venkat/test 38 g++ -o foo.linux foo.C
evadevel07:/usr/evahome/venkat/test 39 ./foo.linux
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579455375671386718750000
evadevel07:/usr/evahome/venkat/test 40 g++ -O -o foo.linux foo.C
evadevel07:/usr/evahome/venkat/test 41 ./foo.linux
51859.435045995065593160688877 * 51421.349407573121425230056047 =
2666682129.579454898834228515625000
evadevel07:/usr/evahome/venkat/test 42

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-12-26 15:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-25 23:19 Floating point differences between solaris and linux Venkatesh Nagarajan
2003-12-26 15:17 John Yates

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).