PEP 238 (revised) (same as above, with typo fixed)
Chris Barker
chrishbarker at home.net
Fri Jul 27 15:57:50 EDT 2001
oops, typo below:
Chris Barker wrote:
>
> > Semantics of Floor Division
> >
> > Floor division will be implemented in all the Python numeric
> > types, and will have the semantics of
> >
> > a // b == floor(a/b)
> >
> > except that the type of a//b will be the type a and b will be
> > coerced into. Specifically, if a and b are of the same type, a//b
> > will be of that type too.
>
> so:
>
> 3//2 == 1
>
> 3.0//2.0 == 1.0
>
> 3.0//2 == 1.0
>
> so if I want to use the result as an index, I'll need to use:
>
> int(x/y)
should be: int(x//y) : the fact that I made that typo does tell me
something about how likely I am to make that kind of typ in code...Oh
Oh!
> kind of like I now use:
>
> int(floor(x/y))
>
> What I don't get, is why // couldn't return an integer always? It will
> always have an integral value. I suppose one problem is that the range
> of integers that a float (C double) can handle is larger than a 32 bit
> integer can hold. This could be solved in the future with int/long
> unification, what will be the behaviour then?
You know, given that I have to use the int() typecast anyway, the //
operator is seeming to be less and less useful. When I want to do floor
division, it is VERY frequently so that I can get an index! IF we define
Python to always do a floor(), rather than a round() when int() is
called, I don't need the // or the floor()
-Chris
--
Christopher Barker,
Ph.D.
ChrisHBarker at home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------
More information about the Python-list
mailing list