PEP 238 (revised)
Chris Barker
chrishbarker at home.net
Fri Jul 27 15:27:44 EDT 2001
> 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)
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
inification, what will be the behaviour then?
-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