This is the mail archive of the gcc-help@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]

Re: 5*1.2 = 5 or 5*1.2 = 6 ?


>>>>> "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


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