Dotan Cohen wrote:
> On 10/09/2007, Bryan Olson <[EMAIL PROTECTED]> 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.

No, Turbo C is yielding the one-and-only correct result with respect
to the C standard:

    (a/b)*b + a%b shall equal a

    (-111/10)*10 + -111%10 shall equal -111

    (-111/10) evaluates to -11 by the truncate-toward-zero rule

    -11*10 + -111%10 shall equal -111

    -110 + -111%10 shall equal -111

    -111%10 shall equal -1


-- 
--Bryan
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to