Q: Feature Wish: "%" Extension

Paul Rubin phr-n2001d at nightsong.com
Sun Nov 4 22:30:19 CET 2001

"Tim Peters" <tim.one at home.com> writes:
> > Knuth says to use floor_mod?  Where?
> Knuth *defines* x mod y as being x - y * floor(x/y), way back in volume 1.
> It simply has the nicest properties when x and y are ints and y > 0.

Yes, x mod y is usually defined that way.  However, "x remainder y"
doesn't necessarily mean the same thing.  The question then is whether
% in a programming language should denote "mod" or "remainder".

> > Every CPU that I know of uses trunc_mod (your 1st variant).
> A great many CPUs have no "mod" instruction at all; most with an integer
> division instruction truncate, possibly due to an unfortunate feedback loop
> involving early Fortran <0.7 wink>.

All integer division instructions I've seen give separate quotient
and remainder results, with remainder==trunc_mod.

> > Floor_mod makes more sense for a lot of things.  I can't help
> > thinking there must be a reason for all the implementations
> > using trunc_mod, but I don't know what it might be.
> Why do almost all PC keyboards have a giant CAP LOCKS key where the CTRL key
> ought to be?  It's not really because they wanted to trick Sun keyboard
> users (or, at least, I hope not <wink>).
> traditionally y'rs  - tim

More information about the Python-list mailing list