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 <stdio.h> #include <stdlib.h> 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