[Python-ideas] Add the imath module
Steven D'Aprano
steve at pearwood.info
Thu Jul 12 12:14:49 EDT 2018
On Thu, Jul 12, 2018 at 06:28:19PM +0300, Serhiy Storchaka wrote:
> This is the one that is useful in many applications and can't be
> trivially written as expression in Python, but is useful in many
> applications (date and time, Fraction, Decimal).
>
> Divide and rounding down: n//m.
> Divide and rounding up: (n+m-1)//m or -((-n)//m).
Sorry, I don't understand why you say that divide and round up can't be
trivially written in Python. Don't you give two implementations
yourself?
I have this in my toolbox:
def ceildiv(a, b):
"""Return the ceiling of a/b."""
return -(-a//b)
and if its buggy, I've never noticed it yet.
--
Steve
More information about the Python-ideas
mailing list