proposed language change to int/int==float (was: PEP0238 lament)

Guido van Rossum guido at python.org
Thu Jul 26 23:18:38 CEST 2001


[Guido]
> >> >The important thing is that i//j will return the same value
> >> >regardless if i and j ar ints or floats; ditto for the new i/j.

[Grant]
> >> If that's important, why won't the other math operators do it???

[Guido]
> >Huh?  They do (apart from unavoidable round-off errors).  1+2 == 1.0+2.0.

[Grant]
> They compare equal with the "==" operator, but they are not
> the same value:
> 
> >>> 1+2
> 3
> >>> 1.0+2.0
> 3.0
> >>> 
> 
> ... unless 3 and 3.0 are "the same value".  In which case my
> definition of that phrase is merely different than yours.

[Guido]
Well, they have the same *mathemtical* value, and Python does its
darndest to treat them as equal everywhere.  For example, a dict with
int keys can be indexed with corresponding float or complex values.
Exceptions are operations that intrinsically require ints, e.g. list
indexing.  (This would change under a unified numeric system though, I
expect, unless inexact numbers are excluded from being used as
sequence indices.)

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list