From mboxrd@z Thu Jan 1 00:00:00 1970 From: mvishnu@calix.com To: gcc-gnats@gcc.gnu.org Subject: c++/3005: improper evaluation of mixed mode expressions involving long long Date: Wed, 30 May 2001 10:46:00 -0000 Message-id: <20010530174334.17941.qmail@sourceware.cygnus.com> X-SW-Source: 2001-05/msg01047.html List-Id: >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 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: