Message86088
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. |
|
Date |
User |
Action |
Args |
2009-04-17 20:13:56 | mark.dickinson | set | recipients:
+ mark.dickinson, gboutsioukis |
2009-04-17 20:13:56 | mark.dickinson | set | messageid: <1239999236.15.0.258925925383.issue1869@psf.upfronthosting.co.za> |
2009-04-17 20:13:54 | mark.dickinson | link | issue1869 messages |
2009-04-17 20:13:54 | mark.dickinson | create | |
|