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]

c++/3005: improper evaluation of mixed mode expressions involving long long



>Number:         3005
>Category:       c++
>Synopsis:       improper evaluation of mixed mode expressions involving long long
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 30 10:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Meenan Vishnu
>Release:        2.95.3
>Organization:
>Environment:
/home/mvishnu/Simulation > g++ -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.3/specs
gcc version 2.95.3 20010315 (release)
/home/mvishnu/Simulation > uname -a
SunOS petuxa08 5.7 Generic_106541-12 sun4u sparc SUNW,Ultra-80
>Description:
#include <iostream>

int main()
  {
    double r;
    int n = 38;
    unsigned long long mi = 16960000;

    r = n * 424 * 1000000 / mi;
    cout << "r = " << r << endl;


    unsigned long long t = n;
    double r1;
    r1 =  t * 424 * 1000000 / mi;
    cout << "r1 = " << r1 << endl;
  }
>How-To-Repeat:
Compile the above (small) program using g++ (version 2.95.3) and run.  The value of r should be 950.  Instead,
it prints r = 1.08766e+12
>Fix:
A simple work around is also shown in the program.  Use
a temporary variable t as shown in the computation of r1.
>Release-Note:
>Audit-Trail:
>Unformatted:


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