This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Nathaniel Manista, Vladimir Feinberg, mark.dickinson, serhiy.storchaka
Date 2022-02-05.16:31:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644078696.12.0.465068726414.issue46639@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2022-02-05 16:31:36mark.dickinsonsetrecipients: + mark.dickinson, serhiy.storchaka, Nathaniel Manista, Vladimir Feinberg
2022-02-05 16:31:36mark.dickinsonsetmessageid: <1644078696.12.0.465068726414.issue46639@roundup.psfhosted.org>
2022-02-05 16:31:36mark.dickinsonlinkissue46639 messages
2022-02-05 16:31:35mark.dickinsoncreate
Morty Proxy This is a proxified and sanitized view of the page, visit original site.