From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17188 invoked by alias); 29 Jul 2002 19:46:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 17169 invoked by uid 71); 29 Jul 2002 19:46:01 -0000 Resent-Date: 29 Jul 2002 19:46:01 -0000 Resent-Message-ID: <20020729194601.17168.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, sewell@dramail.com Received: (qmail 14660 invoked by uid 61); 29 Jul 2002 19:36:42 -0000 Message-Id: <20020729193642.14659.qmail@sources.redhat.com> Date: Mon, 29 Jul 2002 12:46:00 -0000 From: sewell@dramail.com Reply-To: sewell@dramail.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/7437: Identical unsigned int calculations differ by 1, depending on number of steps in calculation. X-SW-Source: 2002-07/txt/msg00775.txt.bz2 List-Id: >Number: 7437 >Category: c >Synopsis: Identical unsigned int calculations differ by 1, depending on number of steps in calculation. >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Mon Jul 29 12:46:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Ken Sewell >Release: gcc version 2.95.3 20010315 (SuSE) >Organization: >Environment: AMD Athlon(tm) Processor SuSE linux 8.0 >Description: a simple calculation of the format a = b / (c / d); e = (unsigned int)a; (where a-d are double and e is an unsigned int) is correct. the calculation e = (unsigned int)(b / (c/d)); is incorrect. if the -O or -O2 flag is given at compile time, the code executes properly. I have also tried this on a Pentium II and with gcc3.0. It does not happen my Sun or SGI systems. >How-To-Repeat: gcc test.c >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="test.c" Content-Disposition: inline; filename="test.c" #include int main () { double x; double dsecs = 3600.0; double step1; unsigned int step2, step1n2; x = 2147483647.0; printf(" x: %f %X\n", x, x); // Do calculations in 2 steps... step1 = dsecs / (3600.0 / x); printf(" step1 = %f / (3600.0 / %f) = %f = %X\n", dsecs, x, step1, step1); step2 = (unsigned int)step1; printf(" step2 = (unsigned int)%f = %u = %X\n\n", step1, step2, step2); // Do calculations in 1 step... step1n2 = (unsigned int)(dsecs / (3600.0 / x)); printf("step1n2 = (unsigned int)(%f / (3600.0 / %f)) = %u = %X\n", dsecs, x, step1n2, step1n2); }