3 ms·
Also, if you need simple (though not necessarily immediately obvious) ceil division, you can do this: -(-a // b) As in: >>> 1 // 2 0 >>> -(-1
by nbadg 9y ago
Also, if you need simple (though not necessarily immediately obvious) ceil division, you can do this:
-(-a // b)
As in:
>>> 1 // 2
0
>>> -(-1 // 2)
1
This works because the floor division is truly a floor (and not a truncate), so floor division of a negative number is "rounded" towards negative infinity, and not towards zero.