Mark Dickinson <dicki...@gmail.com> added the comment:

Here's a patch that improves float rounding in a number of respects:

(1) (when available) it uses the recently added correctly-rounded str <-
> float conversions in Python/dtoa.c.  This means that:

- round(x, n) finally does what the docs say it does:  rounds x to the 
closest multiple of 10**-n (and then returns the closest float to the
result).

- for n > 0, the digits of round(x, n) will always agree with those
  of "%.<n>f" % x.

One *really* nice feature is that since e.g. round(x, 2) will always be 
the closest float to a multiple of 0.01, thanks to the recent repr 
changes it'll always be output with at most two places following the 
decimal point, and so will appear to be properly rounded...

Other changes. round(x, n) now:

(2) deals correctly with large values of n

(3) deals correctly with infinities and nans for x

(4) deals correctly with overflow (e.g. round(1.5e308, -308))

(5) doesn't have the weird exception for n = -2**31+1, which was
treated as a single-parameter round.

Still needs tests.  I'm working on them.

----------
stage:  -> test needed
Added file: http://bugs.python.org/file13714/issue1869.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1869>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to