[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: PATCH: control size of image generated by kimgio_eps_read
From:       Martin Konold <martin () konold ! de>
Date:       2002-02-13 23:51:15
[Download RAW message or body]

On Wednesday 13 February 2002 19:00, Michael Matz wrote:

Hi,

> > Which compiler does not convert a float 1.0 into an IEEE 1.0?
>
> Be aware, that this isn't the issue here. 1.0 is exactly representable in
> IEEE, but it means nothing for the issue at hand.  Intermediate spilling

Exactly e.g.
main() {
 double d=1.0;
 if (d == 1.0l)
   printf("double representation equivalent to long double representation!\n");
 else
   printf("double representation not equivalent to long double 
representation!\n");
}

results in "double representation equivalent to long double representation"

while 

main() {
 double d=0.1;
 if (d == 0.1l)
   printf("double representation equivalent to long double 
representation!\n");
 else
   printf("double representation not equivalent to long double 
representation!\n");
}

results in " double representation not equivalent to long double 
representation!"

This is due to two reasons. Firstly 0.1 is not exactly representable in IEEE 
and secondly I used in my example double and long double instead of float and 
double.

The general rule in the C language is that the smaller of the two operands 
does get converted into the larger before the arithmetic operation is done.

But there is an exception to this implicit conversion rule:

If one of the operands is a float then the other operand is converted to a 
float even if the other operand is a double or long double.

Some may call these oddities while beeing ugly a beautiful sacrifice for 
practicability ;-)

I therefor claim that using the "==" operator for floating point operations 
is generally a bad idea.

Regards,
--martin

-- 
Dipl.-Phys. Martin Konold
Stauffenbergstraße 107, 72074 Tübingen, Germany
email: martin@konold.de
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic