[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 17:33:13
[Download RAW message or body]

On Wednesday 13 February 2002 15:59, Bernd Gehrmann wrote:

Hi,

> > Just use 10.0 (look at the IEEE binary representation) instead of 1.0 and
> > you are already getting problems.
>
> 10.0 = 2^{52+1-53}*10 => An IEEE double with significand 10 and
> exponent 52.
>
> > General rule of thumb never use the "==" operator with floating point but
> > use suitable intervals instead. Please be aware of the fact that the
> > decision to round up or down is implementation dependent and not defined
> > in the standard.
>
> That's nice folklore, but nevertheless wrong ;-) The IEEE standard
> specifies rounding behavior very precisely.

Well, I did not know that it defines the rounding rules for conversions 
between data types. 

I know that it defines rounding rules for arithmetic calculations though.

> For example, it demands that
> an arithmetic operation with a representable result must not have rounding
> errors.

This is simply not true. Of course there are simple cases which violate this 
assumption mainly due to the fact that according to IEEE arithmetic 
operations are cumulative but not associative.

e.g:   (x/y)*y is not necessarily equivalent to x but x * ( y / y ) is always 
equal to x

Take the following example:

#include <stdio.h>
#include <math.h>

main() {
 float x,y,z;
 int    i=0;
 for (x = 1.0; x <= 1000.0 ; x = x + 1.0){
        y = 1.0 / x;
        z = y * x ;
        if (z != 1.0) {printf("%f not perfect for inversion\n",x);
           i++;
         }
  }
  printf("I found a total number of %d non perfect inversions\n",i);
}

I am afraid we are becoming off topic now. Please feel invited to continue 
the thread in private mail.

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