correct round of reals?
Peter Schneider-Kamp
petersc at stud.ntnu.no
Fri May 12 07:13:56 EDT 2000
Hei!
I have put the rint(3) function in the math module. As
Guido observed this is not an ANSI C function and not
available on every platform. Now I want to "simulate"
rint on those insane platforms. What is the Right Way(TM)
to do it?
I have written
double myrint(x) double x; {
return floor(x+0.5);
}
so far, but that does not seem to exhibit the same
behaviour. Problems with this definition:
myrint(2.5) gives 3.0, not 2.0 as rint(3)
myrint(3.5) gives 4.0 as expected
IEEE standard seems to be rounding towards the next
even integer in .5-cases. How do I do that?
Any hints appreciated,
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