Future division patch available (PEP 238)

John W. Baxter jwbaxter at spamcop.com
Sun Jul 22 13:19:31 EDT 2001


In article <mailman.995776716.24336.python-list at python.org>, Guido van
Rossum <guido at digicool.com> wrote:

> - unconditionally, there's a new operator // that will always do int
>   division (and an in-place companion //=).
> 
> - by default, / is unchanged (and so is /=).
> 
> - after "from __future__ import division", / is changed to return a
>   float result from int or long operands (and so is /=).

Given that it is written in stone that 1 / 2 will someday produce 0.5,
then the above seems to be the least bad way to get there.  (And yes,
I've used Pascal extensively for many years, but not recently...so div
wouldn't shock me...but it's not now a keyword and // is a decent
alternative.)

I don't think 1 / 2 producing 0 is broken, so I don't think it needs to
be fixed, but that view is unlikely to prevail.

A note on both case-sensitive and integer division:  if the language
had started out case-insensitive and with / returning float (or
rational) when not exact as integer, I would be against changing the
language to the present rules.  But neither set of rules is broken, and
neither needs to be fixed.  Ah, well...in 20 years it won't matter what
happens now for either issue.

  --John



More information about the Python-list mailing list