Modul (%) in python not like in C?

Dotan Cohen dotancohen at gmail.com
Sun Sep 9 20:13:52 EDT 2007


On 10/09/2007, Bryan Olson <fakeaddress at nowhere.org> wrote:
> Not according to the C standard:
>
>      When integers are divided, the result of the / operator is
>      the algebraic quotient with any fractional part discarded.(87)
>      If the quotient a/b is representable, the expression
>      (a/b)*b + a%b shall equal a.
>      [...]
>      87) This is often called ''truncation toward zero''.
>
>      [International Standard ISO/IEC 9899:1999, Section 6.5.5
>      Multiplicative operators, Paragraph 6 and footnote 87]

This seems most logical to me. Turbo C is against the standard, then.

> > while Python is always consistent and returns positive remainders.
>
> Technically:
>
>      The modulo operator always yields a result with the same sign
>      as its second operand (or zero)
>
>      [http://docs.python.org/ref/binary.html]
>

Again, logical.

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il



More information about the Python-list mailing list