Mark Dickinson <dicki...@gmail.com> added the comment:

I'm not convinced that this deserves to be a math module function. I agree that 
`-(-x // y)`, while simple to write, isn't necessarily obvious. But it does 
have some advantages, like not needing an import, and being naturally 
duck-typed, so that it automatically does the right thing for floats, or 
`fractions.Fraction` objects, or `numpy.int64` objects, or SymPy integers. (Not 
for `Decimal` instances, but that's another story.) Unless we were to add a 
whole __ceildiv__ mechanism, a math module implementation would necessarily be 
limited to integers. (Or perhaps integers and floats.)

There's also the "thin end of the wedge" argument: if ceildiv, why not also 
ceilrem, ceildivrem, rounddiv, roundmod, etc.

The main issue with the `-(-x // y)` spelling seems to be discoverability: if 
everyone knew that this was the right way to spell ceiling division, then there 
wouldn't be a problem. And I'm not convinced that a math.ceildiv function would 
necessarily solve the discoverability problem, either.

So maybe the solution is to advertise the `-(-x // y)` pattern better in 
documentation, for example at the point where floor division is introduced in 
the library reference?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46639>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to