A use for integer quotients
David Eppstein
eppstein at ics.uci.edu
Wed Jul 25 01:55:51 EDT 2001
In article <cpae1tboxg.fsf at cj20424-a.reston1.va.home.com>,
Guido van Rossum <guido at python.org> wrote:
> Well, so far the only arguments I've heard come down to
>
> (1) int/int *ought* to return an int;
>
> (2) it breaks too much code to change now.
As one of the people who posted too much to these threads, I'd like to
clarify my position:
(1') int/int ought to return an exact value.
I'd be happy with int/int=rational (238+228?). Probably happier than with
the status quo. I have code that would break (2) but not too much to
change. You have talked about bad experiences with unpredictable slowdowns
with rationals in ABC, but I would prefer my programs to be correct before
I try to optimize them for speed, and if such a slowdown is found one could
always put in an explicit float() or // or whatever where needed.
If I really believed that (as the mathematicians usually write)
floor(int/int) will mean what it means mathematically, rather than some
worrisome approximation, I would probably use that notation rather than the
ugly int//int (also that way nobody will get confused and think I mean
broken C/C++/Java rounding-towards-zero instead of towards -infty, and I
can use ceiling or round when I mean them instead of adding magic numbers
before doing the division).
Let me also add that I think generators are a really great addition, so
2.2 is still moving in very positive directions even if I don't like
int/int=float.
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list