This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
double error
- From: Bob Hou <yhou at YorkU dot CA>
- To: gcc at gnu dot org, gcc at gcc dot gnu dot org, yhou at YorkU dot CA
- Date: Fri, 31 Jan 2003 12:28:48 -0500
- Subject: double error
Hi,
I have the following simple code and expect the results are all the
same.
However the output is following: (The code is compiled with gcc under
Redhat8.0. )
The result is : 0
The result is : 0
The result is : -2.22045e-15
The code is also tested on MS VS6.0
and it give the same answers (zero).
Could you tell me whether it's a bug or I did sth wrong?
Thanks,
/*--------------- test.c---------------------------*/
#include<stdio.h>
int main()
{
double fi = 0.7509;
double fj = 100.0;
double fk, fk1, fk2 ;
fk = fj*fi - fj*fi;
fk1 = 0.7509*100.0 - 0.7509*100.0;
fk2 = fj*fi - 0.7509*100.0;
printf("The result is : %g\n", fk);
printf("The result is : %g\n", fk1);
printf("The result is : %g\n", fk2);
return 0;
}
/*-----------------end-----------------------------*/
--
__________________________________________________________
Dr. Bob (Yuqian) Hou
Certre for Vision Research
Rm0002B, CSB
York University
4700 Keele Street
North York, Ontario
Canada M3J 1P3
Tel: (416) 736-2100 ext. 66117
Fax: (416) 736-5814