Modul (%) in python not like in C?
mensanator at aol.com
mensanator at aol.com
Mon Sep 10 13:45:31 EDT 2007
On Sep 10, 1:38 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Sun, 09 Sep 2007 22:57:24 -0700, "mensana... at aol.com"
> <mensana... at aol.com> declaimed the following in comp.lang.python:
>
>
>
> > 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?
>
> As I stated, integer division and modulo are linked... Which is
> "correct" is probably dependent upon the language specifications.
I didn't make an opinion on which was "correct".
> Either
> method allows one to recover the original value from the output of
> divmod.
My point was the need to satisfy x = y * a + b doesn't
explain WHY divmod(-70,6) returns (-12,2) instead of (-11,-4).
>
> Whether that works in the way you intend is a different matter -- my
> car loans usually have interest factors which are applied per payment by
> payment date, so using modulo (or divmod) is not applicable, one must
> actually build the table of payments one at a time (especially since the
> automatic payments taken from paychecks gets "corrupted" during
> holidays, when paychecks are issued a day or two earlier than normal,
> meaning less interest charges during that period and more applied to
> principle; with more on interest the following week, and less on
> interest).
Ok, poor example. Suppose instead we are slicing a 70 character string
from the right. We certainly CAN'T have 6 12-letter slices, can we?
But we can have 6 11-letter slices with 4 characters left over.
And there are probably examples where (-12,2) would make more sense,
although I can't think of one at the moment.
Again, I'm not saying (-12,2) is wrong, just that the explanation
why it's (-12,2) is wanting since there are cases where (-11,-4)
makes more sense.
> --
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfr... at ix.netcom.com wulfr... at bestiaria.com
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: web-a... at bestiaria.com)
> HTTP://www.bestiaria.com/
More information about the Python-list
mailing list