Floating point differences between solaris and linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux