How to simulate C style integer division?

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Thu Jan 21 04:58:09 EST 2016


Paul Rubin writes:

> Ben Finney writes:
>> I'm not sure I know exactly what behaviour you want (“C style” may mean
>> different things to each of us).
>
> I thought he meant trunc-division, so -5 / 2 = -2 and -5 % 2 = -1.
> Python specifies floor division but C leaves it unspecified, I thought.

I found a statement that it's specified to be truncating since C99.
Before that it was flooring or truncating.

Reading OP's code, the intention seemed clear to me.



More information about the Python-list mailing list