Message412593
[Tim]
> Because it's a bit obscure, and in real life y is always known to be positive, so the nearly obvious (x + y - 1) // y works fine.
Whereas I find (x + y - 1) // y less obvious at first sight than -(-x // y). :-) I don't care about negative y - that's not my reason for preferring -(-x // y). The preference comes from the fact that -(-x // y) still does the right thing for non-integral cases.
[Vladimir]
> Say we're making a controller for a game engine GUI and need to
figure out how to paint sprites. [...]
For this example, I'd probably just use `ceil(x / y)`. For "real world" things with x and y representing counts of something tangible (pixels, work items, row or column count of a matrix, lines of text, bytes of memory used, ...), you have to go quite a long way before `ceil(x / y)` gives you the wrong answer due to floating-point errors. E.g. if you know the quotient is no larger than 10**6, you're safe for all y <= 10**10. (Or vice versa: if you know the quotient is at most 10**10, then you're safe for y <= 10**6.)
> not __ceildiv__ [...]
It would be a little odd (but only a little) to have __floor__, __ceil__, and __floordiv__ overloads, but not __ceildiv__. It probably wouldn't be long before someone requested it.
I'll quieten down now and wait to see what other people think. |
|
Date |
User |
Action |
Args |
2022-02-05 19:06:49 | mark.dickinson | set | recipients:
+ mark.dickinson, tim.peters, serhiy.storchaka, Nathaniel Manista, Vladimir Feinberg |
2022-02-05 19:06:49 | mark.dickinson | set | messageid: <1644088009.13.0.226015371357.issue46639@roundup.psfhosted.org> |
2022-02-05 19:06:49 | mark.dickinson | link | issue46639 messages |
2022-02-05 19:06:49 | mark.dickinson | create | |
|