c/8395: gcc 2.95.4 and 3.2 generate wrong code for double on intel
Marco Bernardo
bernardo@sti.uniurb.it
Thu Oct 31 00:46:00 GMT 2002
Dear Bruce,
Thanks for your message.
>There's nothing wrong here. It's very reasonable for this code to
>produce ~10^-16 for double.
>The reason is tha the number 1.2 can not be exactly represented as an
>IEEE754 floating point number.
>The numbers 5 and -6 CAN be exactly represented.
I can understand that the problem is related to the IEEE 754
representation.
However, let me point out some weaknesses in your argument:
1. If -1.2 does not have an exact representation,
why is the value of variable y (i.e. -1.2)
correctly displayed through printf?
2. Let us consider the following variant of the program
I attached to my report:
#include <stdio.h>
int main(void)
{
double x, y, z, y_times_z;
x = -6.0;
y = -1.2;
z = 5;
y_times_z = y * z;
printf("%g %g %g %g %g %g\n",
x,
y,
z,
x - y * z,
y_times_z,
x - y_times_z);
return(0);
}
With respect to the previous version, I added
variable y_times_z together with the visualization
of y_times_z as well as x - y_times_z.
Surprisingly enough, the output is
-6 -1.2 5 -2.22045e-16 -6 0
i.e. the correct values are somehow restored.
Now, passing through an additional variable
like y_times_z is how the target code produced
by gcc should be organized, isn't it?
If so, then both x - y * z and x - y_times_z
should evaluate to 0.
Since this is not the case, gcc contains a bug
in the way it translates the arithmetical expressions
when doubles are involved.
In conclusion, I still believe that gcc contains a serious bug
on the intel platform, which should hopefully be fixed asap.
If the bug is fixed, or you or someone else reading this message
is able to point out some flaw in my argument, then my colleagues,
my students, and I will be glad to keep using gcc.
Best regards,
Marco
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Prof. Marco Bernardo
Universita` di Urbino
Centro per l'Applicazione delle Scienze e Tecnologie dell'Informazione
Piazza della Repubblica 13, 61029 Urbino, Italy
Phone: +39-0722-4475 - E-mail: bernardo@sti.uniurb.it
Fax: +39-0722-4475 - WWW: http://www.sti.uniurb.it/bernardo/
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
More information about the Gcc-bugs
mailing list