Bug 11275 - gcc296 and gcc322 leads to different double-type calculation results.
Summary: gcc296 and gcc322 leads to different double-type calculation results.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-20 21:03 UTC by Benjamin Bei
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Bei 2003-06-20 21:03:25 UTC
Hi

I isolated a small program from my original program that leads to a double-type
calculation error. 
When I compile the following prgram using gcc296 and gcc322, they produce
different results. I have looked up in the dug database and am awared of the
problem with -O (optimzation) flag (see
http://gcc.gnu.org/ml/gcc-prs/2000-q2/msg00174.html). I re-compiled without
using any optimzation flag. Though it fixed a few calculation errors in my
orignial program, it still produces different results.

======================== my program  main.cc =================
#include <stdio.h>
#include <math.h>
#include <iostream.h>

void printDouble( double &d)
{
    char st[100];
    sprintf( st, "%.20f", d);    
    cerr << st << endl;
}

int main()
{
    double dS = 0.22683469236471487385;
    double dE = 0.03928836174944403542;
    double iYCount = 86.0;

    double answer = (dS-dE)*log((dS-dE)*iYCount/((iYCount-1.0)*dS)) +
dE*log(dE*iYCount/dS);
    cerr << "Problem: ";
    printDouble( answer);

    return 1;
}

============================== my system ===================
My system is RedHat 9.0. 
The compilers that I am using are gcc296 & gcc322

$ gcc296 -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux7/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-118)
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)



========================== compilation step =====================
gcc main.cc -lm -lnsl -dl -ltcl -lstdc++ -g -Wall -o main.gcc322

gcc296 main.cc -lm -lnsl -dl -ltcl -lstdc++ -g -Wall -o main.gcc296


========================== actual results =======================
$ ./main.gcc296
Problem: 0.07264305087503322711
$ ./main.gcc322
Problem: 0.07264305087503321323


========================== expected results =====================
both printed values should be the same.


Thank you for looking into the problem. Feel free to contact me at
benjamin.bei@rtc.bosch.com or 650-320-2943
Comment 1 Wolfgang Bangerth 2003-06-21 00:33:52 UTC
This is not a bug. The two numbers coincide up to their 16th digit,
so the difference is entirely in the last bit. This may be due to 
different order of operands, or the weird x86 floating point
model.

W.