correct round of reals?

Peter Schneider-Kamp petersc at stud.ntnu.no
Sat May 13 08:42:49 EDT 2000


"Dennis E. Hamilton" wrote:
> 
> It seems easy enough to tell if IEEE rounding is being done in this
> case.  Convert some simple fractional values that have exact
> representations in IEEE floating point and confirm that you get the
> expected result.

Hei Dennis!

My concern is less about wether IEEE rounding is done on a specific
platform but that I want to do IEEE rounding
(to-nearest-integer-or-whatever-it-is-called mode) for platforms
that do not export the rint(3) function. There is HAVE_RINT from
the configure script (thanks to Guido for the configure magic)
which tells me whether this function is available. Now I feel it
is a good idea to provide a function rint which behaves exactly
the same on those platforms where HAVE_RINT is not set.
The problem lies int the "behaves exactly" part.

> 2. A more important question may be, what you want the integer result
> for?  There is nothing sacred about the IEEE rounding rule although it
> offers a kind of mathematical purity.  If your desire is to preserve
> exact arithmetic, you may be better of scaling everything to integers
> (even the python long integer, if you need more than about 15 digits),
> only showing decimal fractions in the output.  If fractional
> intermediate results are possible, you then have further questions to
> answer concerning how to reduce intermediate results to integers for use
> in further calculations.  This surfaces all of the questions that we
> sweep under the carpet by blindly using floating-point calculations.  I
> guess this is what people mean about the difference between accuracy and
> precision!

As said above I want math.rint to behave consistent across different
platforms. More directly put I want to have deterministic behaviour
for my python code. If I do math.rint(3.5) and get 4.0 I want to
get it on all platforms.

So what I want is determinism by consistency. I personally do not
care about accuracy or precision.

> The pyNum folks may have dealt with fine rounding control of the IEEE
> floating-point unit, because control of the rounding mode is often
> important in assuring the accuracy of numerical functions.  You may have
> to look in the C Libraries underneath pyNum for ideas of what you might
> be able to use from there.  I haven't looked myself so this is a wild
> guess.

Good idea. I should ask them.

really-astonished-how-floating-point-arithmetic-turns-
out-to-be-such-a-beast-ly y'rs 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