Modul (%) in python not like in C?

Matthew Woodcraft mattheww at chiark.greenend.org.uk
Tue Sep 11 19:00:52 CEST 2007


J. Cliff Dyer <jcd at sdf.lonestar.org> wrote:
>Bryan Olson wrote:
>> Not true. Here it is again:
>>
>>      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]


> But C was around for a long time before the 1999 standard.  C89,
> commonly called ANSI C, is still very commonly used in compilers, and
> K&R C goes back to 1972.  Is truncation toward 0 the standard for K&R C
> as well? 

As I remember, the behaviour for negative 'a' wasn't specified in K&R C
or in C89; the rule was tightened up for C99.

-M-




More information about the Python-list mailing list