This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Floating poing 'non-bug'? Or is this a bug?
- From: Erik de Castro Lopo <gcc-erikd at mega-nerd dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 6 Jul 2004 17:46:05 +1000
- Subject: Re: Floating poing 'non-bug'? Or is this a bug?
- Organization: Erik Conspiracy Secret Labs
- References: <10eb01c4632b$b915be50$3b0111ac@il.mainsoft.com>
On Tue, 6 Jul 2004 10:34:51 +0300
"Yuval Kfir" <yuvalk@mainsoft.com> wrote:
> Hello,
> I posted this to gcc-bugs but received no response, perhaps someone here can
> help me...
>
> The short program below gives '5*1.2=5' when compiled
> without -DDOUBLE_INTER, but '5*1.2=6' with the double-precision intermediate
> variable.
> Is this the same old non-bug? Why would it behave differently when storing
> the result temporarily in a double?
In the case of:
i *= 1.2 ;
the compiler converts 1.2 to the nearst integer (1) and them multiples i
by 1 and assigns that value to i.
In the case of :
double g = i * 1.2;
i = g;
the variable i is promoted to a double, multiplied by a double and the
result (6.0) is assigned to g. Then, the nearest integer value to g is
assigned to i.
This is not a bug, but a direct result of how numbers are handled by
the C language.
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners." -- Ernst Jan Plugge