[Python-ideas] Round division
storchaka at gmail.com
Fri Sep 11 00:39:59 CEST 2015
On 11.09.15 00:48, Paul Moore wrote:
> On 10 September 2015 at 22:13, Mark Young <marky1991 at gmail.com> wrote:
>> Pardon my ignorance, but what is the definition of round division? (if it
>> isn't "round(a/b)")
> I assumed it would be "what round(a/b) would give if it weren't
> subject to weird floating point rounding issues". To put it another
> way, if a / b is d remainder r, then I'd assume "round division" would
> be d if r < b/2, d+1 if r > b/2, and (which of d, d+1?) if r == b/2.
> (a, b, d and r are all integers).
> If not, then I also would like to know what it means...
Yes, it is what you have described. If r == b/2, the result is even
> Either way, if it is introduced then it should be documented
> (particularly as regards what happens when one or both of a, b are
> negative) clearly, as it's not 100% obvious.
> Also, is the math module the right place? All of the operations in the
> math module (apart from factorial, for some reason...) are floating
It is the best place in the stdlib. Apart from floating point functions,
the math module contains integer functions (factorial and gcd) and
general number functions (floor, ceil, trunc and isclose). gcd and
isclose are new in 3.5.
More information about the Python-ideas