Modul (%) in python not like in C?

J. Cliff Dyer jcd at sdf.lonestar.org
Tue Sep 11 06:41:51 EDT 2007


Bryan Olson wrote:
> Scott David Daniels wrote:
>   
>> C, which was designed as a "high level assembly language," does not
>> tightly define the results of / and % for negative numbers.  Instead
>> it defines the result for positive over positive, and constrains the
>> result for the others. 
>>     
>
> 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? 

Cheers,
Cliff



More information about the Python-list mailing list