This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]