Message412580
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? |
|
| Date |
User |
Action |
Args |
| 2022-02-05 16:31:36 | mark.dickinson | set | recipients:
+ mark.dickinson, serhiy.storchaka, Nathaniel Manista, Vladimir Feinberg |
| 2022-02-05 16:31:36 | mark.dickinson | set | messageid: <1644078696.12.0.465068726414.issue46639@roundup.psfhosted.org> |
| 2022-02-05 16:31:36 | mark.dickinson | link | issue46639 messages |
| 2022-02-05 16:31:35 | mark.dickinson | create | |
|