[Python-ideas] Round division
Serhiy Storchaka
storchaka at gmail.com
Thu Sep 10 22:01:20 CEST 2015
In Python there is a operation for floor division: a // b.
Ceil division easy can be expressed via floor division: -((-a) // b).
But round division is more complicated. This operation is needed in
Fraction.__round__, in a number of methods in the datetime module (see
_divide_and_round). Due to the complexity of the correct Python
implementation, it is slower then just division.
I propose to add special function in the math module. This not only will
speed up Python implementation of the datetime module and the fractions
module, but will encourage users to use correct algorithm instead of
obvious but incorrect round(a/b).
More information about the Python-ideas
mailing list