[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: operation of 'round' function

From: David Kastrup
Subject: Re: operation of 'round' function
Date: 07 Feb 2002 17:13:16 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

address@hidden (Ronan Waide) writes:

> This may be a bug, or may simply be a failure of understanding on my
> part. However.
> GNU Emacs 20.7.1 (i386-redhat-linux-gnu, X toolkit) of Mon Jul 30 2001
> on stripples.devel.redhat.com
> (round 0.5) = 0
> (round 1.5) = 2
> (round 2.5) = 2
> (round 3.5) = 4
> (round 4.5) = 4
> and so forth. It appears to be rounding to the nearest /even/
> integer. The docstring says:
> "Return the nearest integer to ARG."
> Which should have returned 1, 2, 3, 4, 5 above.

That does not follow.  Quite as the docstring says, it returns the
nearest integer to ARG in case such a nearest integer exists.  In the
case of 0.5, 0 and 1 are equally near.

The doc string is incorrect as far as it does not even consider this

The numerical convention for rounding is to round in ambiguous cases
like that to the nearest even integer if the number base is not
dividable by 4, and to round to the nearest odd integer if it is.
That way, the rounding is
a) unbiased
b) moves away from values which might appear ambiguous in a subsequent
rounding step

So the doc string should be amended to read
"Return the nearest integer to ARG.  In case ARG lies equally close to
the next and previous integer"
and then we'd need the proper statement, something like
a) "the behaviour depends on the floating point implementation of the
underlying machine Emacs is running on"
b) "the next even integer is chosen in compliance with IEEE
c) "Emacs consults the variable rounding-direction which
can take on the values 't, 'nil or 'randomly meaning..."

David Kastrup, Kriemhildstr. 15, 44793 Bochum
Email: address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]