Q: Feature Wish: "%" Extension

John Roth johnroth at ameritech.net
Mon Nov 5 18:57:45 EST 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1004908205.3765.python-list at python.org...
> [Tim]
> > An odd thing is that, when this comes up, people complain that under
> > Python's current rules it's not necessarily the case that
> >
> >     (-i)/j == -(i/j)
> >
> > Across decades of integer numeric programming, I can't recall any
> > *use* for that identity; but that i%j >= 0 whenever j>0 is endlessly
> > useful, as is your identity relating int-div and int-mod.
>
> [John Roth]
> > Useful as it is, it makes division not be the
> > inverse of multiplication, so it's mathematically incorrect,
> > and hence astonishing to people who don't know the score.
>
> What does "it" mean?  Sorry, but I can't make sense out of your
comment.  I
> was talking about truncating integer divsion versus flooring integer
> division; i/j == k does not imply i == j*k under either of those.

The basic sign rules for multiplication are so clear that I don't
really need to repeat them here. If division is the inverse of
multiplication, then the sign rules follow directly. Any definition
of division which does not do that isn't an inverse of multiplication,
but some other operation masquerading under the same name.

This might be a much more useful operation in practice, but
it is confusing to someone who expects the system to behave
the way he was taught in grammer school.

In other words, (-i)/j should  -(i/j).

John Roth
>
>





More information about the Python-list mailing list