Q: Feature Wish: "%" Extension

John Roth johnroth at ameritech.net
Wed Nov 7 11:31:11 EST 2001


"Rainer Deyke" <root at rainerdeyke.com> wrote in message
news:9gbG7.58629$IR4.32167958 at news1.denver1.co.home.com...
> "Hans Nowak" <wurmy at earthlink.net> wrote in message
> news:3BE9338B.70257B81 at earthlink.net...
> >
> > Rainer Deyke wrote:
> >
> > > "John Roth" <johnroth at ameritech.net> wrote in message
> > > news:tugphsjop81s04 at news.supernews.com...
> > > > Integer division is not an inverse of integer multiplication,
> therefore
> > > > the proposed counterexample fails.
> > >
> > > What do you mean?  '(a * b) / b' equals 'a' for all integers 'a'
and 'b'
> > > (assuming 'a * b' evaluates without overflow), except when 'b'
equals 0.
> >
> > I think the idea is that (a / b) * b does not equal a in current
> > (non-__future__) Python...?
> >
> > >>> (9 / 4) * 4
> > 8
>
> That would be a multiplication problem, wouldn't it?  By the same
token, we
> could want '(2 * 0) / 0 == 2'.  It is the nature of integer
multiplication
> that 'a * b' yields a multiple of 'b'.  Integer division is the
inverse of
> that, except that you can't divide by zero.  If you feed it input that
isn't
> the result of multiplication, it's your own damn fault.

That's an interesting point, but it restricts 'legitimate' integer
divisions
to those that have a zero remainder. Since I doubt that there is any
use for an integer divide operation that throws an exception if the
remainder is not zero, the case isn't interesting.

Since the original point had to do with sign handling, I'd be
quite willing to restrict the discussion to your definition of
integer division; sign handling for cases where there is a
non-zero remainder fall out of this very naturally.

John Roth
>





More information about the Python-list mailing list