correct round of reals?

Peter Schneider-Kamp petersc at stud.ntnu.no
Sat May 13 04:55:05 EDT 2000


Fredrik Lundh wrote:
> 
> def rint(v, m=4503599627370496.0):
>     if abs(v) > m:
>         return v
>     if v > 0:
>         return (v + m) - m
>     else:
>         return (v - m) + m

That is very nice and works fine in Python, but the
romans don't go home in that "C" language:

#define MAX_DOUBLE_INT 4503599627370496.0
double rint(x) double x; {
        if (abs(x) > MAX_DOUBLE_INT)
                return x;
        if (x > 0)
                return (x+MAX_DOUBLE_INT)-MAX_DOUBLE_INT;
        else
                return (x-MAX_DOUBLE_INT)+MAX_DOUBLE_INT;
}

Using this rint in the mathmodule.c I get:
math.rint(0.7) == 0.700195

What's wrong?

confused-about-the-python-transcending-c-ly yours
Peter
--
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter at schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de





More information about the Python-list mailing list