Nasty typo in PEP 238 (revised)
Tom Jenkins
tjenkins at nospiced.ham.devis.com
Thu Jul 26 22:34:55 EDT 2001
David Eppstein wrote:
> In article <cp4rrz5onj.fsf at cj20424-a.reston1.va.home.com>,
> Guido van Rossum <guido at python.org> wrote:
>
>
>> Q. How do I write code that works under the classic rules as well
>> as under the new rules without using // or a future division
>> statement?
>>
>> 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)
>>> xxx = 1.0
>>> yyy = 2
>>> from math import floor
>>> floor(xxx)/yyy
0.5
>>> xx = 1
>>> floor(xx)/yyy
0.5
>>> yy = 2
>>> floor(xx)/yy
0.5
>>> floor(xx)
1.0
>>> xx = -1
>>> floor(xx)
-1.0
>>> floor(xx)/yy
-0.5
>>>
so-i-guess-it's-not-a-typo-ly yours
Tom
More information about the Python-list
mailing list