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]

Re: Floating poing 'non-bug'? Or is this a bug?


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


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