On Sep 9, 11:43?pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Mon, 10 Sep 2007 01:06:59 GMT, Bryan Olson <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
> > They also disagree about integer division. C rounds toward zero;
> > Python rounds downward.
>
> > In C:       -111 / 10  evaluates to -11
> > In Python:  -111 / 10  evaluates to -12
>
> > > Is this a known gotcha? I tried to google the
> > > subject however one cannot google the symbol %.
>
> > I think it's a known gotcha. I cited the refs in another post.
>
>         The best answer is probably to be found from the definition of
> divmod()
>
>
>
> >>> divmod(70, 6)
> (11, 4)
> >>> 6*11 + 4
> 70
> >>> divmod(-70, 6)
> (-12, 2)
> >>> 6 * -12 + 2
> -70
>
> Or in general terms
>
> (a, b) = divmod(x, y)
> x = y * a + b

But, in general, doesn't (-11,-4) also satisfy
  x = y *   a +   b
-70 = 6 * -11 + (-4)?

Do you overpay your car loans and wait for a refund?

Or do you make your last payment the residue of the
debt after making 47 (or whatever) equal payments?


>
> IOWs, the definition of modulo, and the definition of integer division,
> are linked...
>
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         [EMAIL PROTECTED]             [EMAIL PROTECTED]
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               [EMAIL PROTECTED])
>                 HTTP://www.bestiaria.com/


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

Reply via email to