This is the mail archive of the gcc-bugs@gcc.gnu.org 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]

[Bug c++/11275] New: gcc296 and gcc322 leads to different double-type calculation results.


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11275

           Summary: gcc296 and gcc322 leads to different double-type
                    calculation results.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: benjamin.bei@rtc.bosch.com
                CC: gcc-bugs@gcc.gnu.org

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


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