[Python-Dev] Return type of round, floor, and ceil in 2.6 (original) (raw)
Guido van Rossum guido at python.org
Sat Jan 5 17:54:44 CET 2008
- Previous message: [Python-Dev] Return type of round, floor, and ceil in 2.6
- Next message: [Python-Dev] Return type of round, floor, and ceil in 2.6
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Jan 4, 2008 10:16 PM, <glyph at divmod.com> wrote:
On 4 Jan, 10:45 pm, python at rcn.com wrote: >[GvR to Tim] >>Do you have an opinion as to whether we should >>adopt round-to-even at all (as a default)? > >For the sake of other implementations (Jython, etc) and for ease of >reproducing the results with other tools (Excel, etc), the simplest >choice is int(x+0.5). That works everywhere, it is easy to explain, it >runs fast, and it is not hard to get right.
I agree for the default. Except the part where Excel, Jython, and Python's current round, actually use sign(x) * int(abs(x)+0.5), so maybe it's not completely easy to get right ;-). Having other rounding methods available, though, would be neat. The only application I've ever worked on where I cared about the difference, the user had to select it (since accounting requirements differ by jurisdiction and, apparently, by bank preference). Having a standard way to express this (especially if it worked across different numeric types, but perhaps I digress) would be pleasant. Implementing stochastic rounding and banker's rounding oneself, while not exactly hard, is a drag.
The decimal module already supports rounding modes in its context. For other types, perhaps converting to decimal might be good enough?
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Return type of round, floor, and ceil in 2.6
- Next message: [Python-Dev] Return type of round, floor, and ceil in 2.6
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]