[Fwd: Comment on PEP-0238]
Chris Gonnerman
chris.gonnerman at newcenturycomputers.net
Sat Jul 7 15:03:43 EDT 2001
----- Original Message -----
From: "Guido van Rossum" <guido at digicool.com>
> > However, I think that some details of the numerics also need to
> > be clarified before you boldly go. Specifically,
> >
> > - What about long division? A float cannot capture all results.
> > Should it raise a Value/Range error?
> > Should the programmer be forced to use divmod?
> > Should it return a rational?
> > I don't really like the last two choices and the first two choices
> > obviate much of the usefulness of longs.
>
> We'll introduce a new operator or function (e.g. div(x, y)) for
> integer division, which will work for ints and longs. When / is used
> and the result can't be expressed as a C double, we can choose between
> yielding Infinity or raising OverflowError; I think probably the
> latter although with two float arguments this currently returns Inf on
> most platforms.
Perhaps it's too inconsistent, but I see no reason why longs can't continue
returning "normal" results forever. When you use a long you know what you
are
doing, or at least think you do; so you should expect integer division
results
just as always.
What does it buy us to break longs as well as ints?
Overall I am in favor of *eventually* automatically promoting ints to float
when division is attempted, and likewise converting longs to floats when
dividing one by the other, but I really think we gain nothing by changing
the semantics of division of longs.
I would also say that, when longs and ints are divided together, you should
probably promote the int to a long rather than performing float division.
In other words:
int / int => float
float / float => float
long / long => long
int / float => float
float / int => float
int / long => long
long / int => long
long / float => long
float / long => long
I have a bad feeling about raising an exception on int division, but I
really
can't say what is so bad about it... maybe that it seems messy. Division of
a numeric value should yield some kind of numeric value, except in the case
of division by zero, etc. I really don't think a newbie will appreciate
>>> 1 / 2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
IntDivisionError: integer division is invalid
any more than they currently understand
>>> 1 / 2
0
More information about the Python-list
mailing list