How to simulate C style integer division?

Random832 random832 at fastmail.com
Thu Jan 21 14:52:08 EST 2016


On Thu, Jan 21, 2016, at 09:31, Marko Rauhamaa wrote:
> Maybe:
> 
>    def intdiv(a, b):
>        return a // b if (a < 0) == (b < 0) else -(-a // b)

Personally, I like a // b + (a % b and a ^ b < 0) - I've done the
opposite in C to get python-style division.



More information about the Python-list mailing list