This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: 5*1.2 = 5 or 5*1.2 = 6 ?
- From: Momchil Velikov <velco at fadata dot bg>
- To: "Jocelyn Fournier" <joc at presence-pc dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: 16 Jul 2002 14:28:28 +0300
- Subject: Re: 5*1.2 = 5 or 5*1.2 = 6 ?
- References: <026901c22cb1$f1631030$d06a0e50@presencey59n1y>
>>>>> "Jocelyn" == Jocelyn Fournier <joc@presence-pc.com> writes:
Jocelyn> #include <stdio.h>
Jocelyn> main()
Jocelyn> {
Jocelyn> int x = 5;
Jocelyn> x *= 1.2;
Jocelyn> printf("5 x 1.2 = %d\n", x);
Jocelyn> }
Jocelyn> I've compiled it with gcc 3.1
Jocelyn> First try :
Jocelyn> gcc -o code1 code1.c
Jocelyn> [root@forum] /home/joce> ./code1
Jocelyn> 5 x 1.2 = 5
Jocelyn> Second try :
Jocelyn> gcc -O -o code1 code1.c
Jocelyn> [root@forum] /home/joce> ./code1
Jocelyn> 5 x 1.2 = 6
Jocelyn> Why does the compiler return a different result if the -O is used ?
Differend rounding performed by the program (with no optimizations)
and the compiler (with optimizations).
~velco