How to simulate C style integer division?

Grobu snailcoder at retrosite.invalid
Sat Jan 23 07:52:58 EST 2016


> def intdiv(a, b):
>      return (a - (a % (-b if a < 0 else b))) / b
>
>

Duh ... Got confused with modulos (again).

def intdiv(a, b):
     return (a - (a % (-abs(b) if a < 0 else abs(b)))) / b




More information about the Python-list mailing list