From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17287 invoked by alias); 19 Jun 2008 14:20:02 -0000 Received: (qmail 17091 invoked by uid 48); 19 Jun 2008 14:19:17 -0000 Date: Thu, 19 Jun 2008 14:20:00 -0000 Subject: [Bug middle-end/36578] New: cast to long double not taken into account when result stored to a double X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "vincent at vinc17 dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-06/txt/msg01154.txt.bz2 The following program shows that the casts to long double are not taken into account when the result to stored to a variable of type double. This bug occurs with gcc from 3.4 to 4.3.1, but didn't occur with gcc 3.3. The bug can be reproduced on a Linux/x86_64 machine (i.e. where the "double" type corresponds to the IEEE-754 double precision and the "long double" type corresponds to the traditional x86 extended precision) with the arguments: 4294967219 4294967429 (these arguments allow the double rounding effect to be visible). #include #include int main (int argc, char **argv) { double a, b, c, d, e; long double al, bl, dl, el; if (argc != 3) exit (1); a = atof (argv[1]); b = atof (argv[2]); al = a; bl = b; c = a * b; d = (long double) a * (long double) b; e = al * bl; dl = (long double) a * (long double) b; el = al * bl; printf ("a = %.0f\n", a); printf ("b = %.0f\n", b); printf ("c = %.0f\n", c); printf ("d = %.0f\n", d); printf ("e = %.0f\n", e); printf ("dl = %.0Lf\n", dl); printf ("el = %.0Lf\n", el); return 0; } Incorrect result (with gcc 3.4 to gcc 4.3.1): a = 4294967219 b = 4294967429 c = 18446744314227707904 d = 18446744314227707904 e = 18446744314227712000 dl = 18446744314227709952 el = 18446744314227709952 Correct result (as given by gcc 3.3) is the same except: d = 18446744314227712000 Note: I compiled with the options -std=c99 -Wall -pedantic. -- Summary: cast to long double not taken into account when result stored to a double Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vincent at vinc17 dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36578