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: "Jocelyn Fournier" <joc at presence-pc dot com>
- To: "Momchil Velikov" <velco at fadata dot bg>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Tue, 16 Jul 2002 13:33:11 +0200
- Subject: Re: 5*1.2 = 5 or 5*1.2 = 6 ?
- Organization: Presence-PC
- References: <026901c22cb1$f1631030$d06a0e50@presencey59n1y> <873cuj3o9v.fsf@fadata.bg>
- Reply-to: "Jocelyn Fournier" <joc at presence-pc dot com>
Hi,
Thank you for your answer.
What kind of optimisations are done in the case where the -O switch is used
?
Regards,
Jocelyn
----- Original Message -----
From: "Momchil Velikov" <velco@fadata.bg>
To: "Jocelyn Fournier" <joc@presence-pc.com>
Cc: <gcc-help@gcc.gnu.org>
Sent: Tuesday, July 16, 2002 1:28 PM
Subject: 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
>
>
>