Nasty typo in PEP 238 (revised)
David Eppstein
eppstein at ics.uci.edu
Fri Jul 27 06:12:08 CEST 2001
In article <3B60D432.5060109 at nospiced.ham.devis.com>,
Tom Jenkins <tjenkins at nospiced.ham.devis.com> wrote:
> >> A. Use x*1.0/y for true division, divmod(x, y)[0] for int
> >> division. Especially the latter is best hidden inside a
> >> function. You may also write floor(x)/y for true division if
> >> you are sure that you don't expect complex numbers.
> >>
> >
> >
> > Shouldn't this be float(x)/y ?
> >
> > I still don't like the phrase "true division", it implies a value judgement
> > that quotients are somehow an inferior thing to want to compute.
> >
>
> David,
> I'm not sure. I thought so to, but decided to try it in the interpreter
> first (since I never used floor before)
floor converts ints to floats???? This seems exactly backwards from what I
would expect. And while it is certainly documented that way in the library
reference (section 5), it is contradicted by the footnote in section 2
about using floor and ceil for "well-defined conversions" from float to
int, as well as the claim in the reference manual that integer-division is
the same as applying floor to the result of mathematical division.
I have to consider this a big wart.
Especially with the proposed changes to /, I would likely want to write
code like i = floor(a/b) and j = ceil(c/d) but apparently this is going to
need added coercions to get an integral type.
Anyway, back to the PEP, I don't think calling floor(x) is a very clear way
of writing an int-to-float coercion, and it's still a bug because it will
give you incorrect results if x is a non-integral 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