[Numpy-discussion] bug in round with negative number of decimals
A. M. Archibald
peridot.faceted at gmail.com
Mon Sep 4 00:53:40 CDT 2006
On 04/09/06, Sebastian Haase <haase at msg.ucsf.edu> wrote:
> Thanks for the reply - but read what the doc says:
> >>> N.around.__doc__
> 'Round 'a' to the given number of decimal places. Rounding
> behaviour is equivalent to Python.
> Return 'a' if the array is not floating point. Round both the real
> and imaginary parts separately if the array is complex.
> it is *not* done this way in Python:
> >>> round(.5)
> >>> round(1.5)
> >>> round(2.5)
> ( the round obj. method is missing this doc string )
Um, well, the doc is wrong. Numpy should *not* always follow python's
lead, and in partciular it's explicit that Numeric's floating point is
closer to IEEE floating-point behaviour than python's - compare, for
example 1./0. and array(1.)/0.
> I really think we should stick to what the doc string say - everybody
> expects x.5 to round up !!
Not everybody. This (admittedly odd) behaviour wasn't decided on
because it was more efficient to implement, it was decided on because
a group of very smart numerical analysts agreed that it was the best
way to avoid surprising naive users with biased results. (Non-naive
users can normally pick from any of several other rounding modes if
A better question to ask is, "Can I change numpy's rounding behaviour
for my programs?" (And, more generally, "can I set all the various
floating-point options that the IEEE standard and my processor both
support?") I don't know the answer to that one, but it does seem to be
a goal that numpy is trying for (hence, for example, the difference
between numpy float scalars and python floats).
A. M. Archibald
More information about the Numpy-discussion