Q: Feature Wish: "%" Extension

Tim Peters tim.one at home.com
Sun Nov 4 22:00:02 CET 2001


[Paul Rubin]
> 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.

> 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>.

> 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