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, tim.peters
Date 2022-02-05.19:06:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644088009.13.0.226015371357.issue46639@roundup.psfhosted.org>
In-reply-to
Content
[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.
History
Date User Action Args
2022-02-05 19:06:49mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, serhiy.storchaka, Nathaniel Manista, Vladimir Feinberg
2022-02-05 19:06:49mark.dickinsonsetmessageid: <1644088009.13.0.226015371357.issue46639@roundup.psfhosted.org>
2022-02-05 19:06:49mark.dickinsonlinkissue46639 messages
2022-02-05 19:06:49mark.dickinsoncreate