From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12948 invoked by alias); 18 Sep 2002 14:04:10 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 12940 invoked from network); 18 Sep 2002 14:04:07 -0000 Received: from unknown (HELO mail.bcpl.net) (204.255.212.10) by sources.redhat.com with SMTP; 18 Sep 2002 14:04:07 -0000 Received: from webmail.bcpl.net (webmail.bcpl.net [204.255.212.24]) by mail.bcpl.net (8.11.3/8.11.3) with ESMTP id g8IE3iv23058 for ; Wed, 18 Sep 2002 10:03:48 -0400 (EDT) X-WebMail-UserID: sabbahem Date: Wed, 18 Sep 2002 07:04:00 -0000 From: "Hillel (Sabba) Markowitz" To: GCC Help X-EXP32-SerialNo: 00002700 Subject: linux i-86 problem with rounding (gcc-3.1.1 & 3.2) Message-ID: <3DA44C07@webmail.bcpl.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-SW-Source: 2002-09/txt/msg00129.txt.bz2 The following test program give incorrect results in a cast from double to int when compiled without an optimization option but correct results when compiled with an optimization option. int main(int argc, char **argv) { int i = 128000; double f = 0.0075; double g; unsigned int u; u = (unsigned int) (i*f); printf("unsigned int result of i*f: %u\n", u); g = i*f; u = (unsigned int)g; printf("double result: %lf\n", g); printf("unsigned int result: %u\n", u); return(0); } %gcc testfloat.c -o testfloat %./testfloat unsigned int result of i*f: 959 double result: 960 unsigned int result: 960 %gcc testfloat.c -o testfloat -O %./testfloat unsigned int result of i*f: 960 double result: 960 unsigned int result: 960 This error occurs only on the linux i-86 (redhat 7.2 or 7.3). However, the results come out correctly on Solaris, DEC (4.0 and 5.1) and linux alpha (redhat 7.2). Does anyone have an idea for a fix or workaround? Is this an artifact of the Assembler or the floating point co-processor? Is this something to do with gcc? Please e-mail me with the answer as well as the mailing list. Thanks, -- Said the fox to the fish, "Join me ashore". The fish are the Jews, Torah is our water Hillel (Sabba) Markowitz - sabbahem@bcpl.net