[Python-Dev] Return type of round, floor, and ceil in 2.6
glyph at divmod.com
glyph at divmod.com
Sat Jan 5 07:16:09 CET 2008
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.
More information about the Python-Dev
mailing list