Comment on PEP-0238
Guido van Rossum
guido at python.org
Wed Jul 11 16:19:39 CEST 2001
Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> writes:
> Mon, 09 Jul 2001 18:19:10 GMT, Terry Reedy <tjreedy at home.com> pisze:
> > I thought the desire was/is to have an operator which just preserved int /
> > int -> int. But I have never seen it specified whether float div whatever
> > would be an error or have the current meaning (in which case confirmation
> > would not be necessary).
> I would prefer it to mean integer division of fractional numbers, e.g.
> 1.3 div 0.3 == 4
> 1.3 mod 0.3 == 0.1
> The question whether div should return int or long (or even fractional
> with integral value) becomes irrelevant when ints and longs are unified
> (even if "unified" means that operations on ints return longs instead
> of raising overflow, keeping types distinct).
Indeed, x div y (or x//y, or div(x, y)) will be defined as
divmod(x, y). This is already defined for floats and returns an
integer value with a float type.
By the way (this is for Terry :-), int/int in Python does not do the
same as it does in C for negative operands.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list