Re: Integer division, surprising results

From: Steve (dippyd_at_yahoo.com.au)
Date: 05/12/04


Date: Wed, 12 May 2004 13:52:24 +1000

Rory Geoghegan wrote:
>>I've looked at faqs and documentation, and nothing jumped out at me. Can
>>anyone explain the reasoning for this?
>
>
> According to my math book integer division is defined as such:
> a/b = q, where a = b*q + r and r is the remainder.
>
> A remainder (ei a modulo) is always positive, effectively flooring all
> the division operations.

Remainders are always positive, but modulo can be
defined as either positive or negative (for negative
arguments). There are pros and cons for doing it either
way, although the Python way seems to have more pros
than cons.

-- 
Steven D'Aprano


Relevant Pages

  • Whos the man in NY?
    ... News votes for Pedro as king of New York ... Pros: The Mets may be destined to be a .500 team this season, ... Cons: ... The Yankees are his daddy. ...
    (alt.sports.baseball.ny-mets)
  • SUMMARY: how do you manage documentation?
    ... Pros: existing docs can remain in native format, user logins, version control ... Cons: need to setup MySQL or Postgresql ... "I don't create documentation for others to use. ... therefore, doesn't consume proprietary files ...
    (SunManagers)
  • Re: Whos the man in NY?
    ... > Every era in New York sports history has The Man, ... Below, you'll find our rankings, with pros and cons ... The Yankees are his daddy. ...
    (alt.sports.baseball.ny-mets)
  • Re: NC State bouncyball coaching search
    ... coach, as they see it." ... Pros and Cons: ... recruiter with today's young athletes. ...
    (rec.sport.football.college)
  • Re: SMT Informational survey for 2004
    ... >> WHAT IS YOUR PREFERRED ATTIRE TO TRANSCRIBE IN? ... I like it very quiet. ... >> WHAT DO YOU FIND ARE THE PROS AND CONS OF WORKING THE WAY YOU DO? ...
    (sci.med.transcription)

Loading