# [Python-ideas] Round division

Chris Barker chris.barker at noaa.gov
Fri Sep 11 01:08:59 CEST 2015

On Thu, Sep 10, 2015 at 3:39 PM, Serhiy Storchaka <storchaka at gmail.com>
wrote:

> 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 (i.e.
> (d+1)//2*2).
>
> 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
>> point.
>>
>
> 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.

well, floor, ceil, and isclose are all about floats...

Nevertheless, yes the math module is the place for it.

-CHB

>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150910/3a878153/attachment-0001.html>