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

David Eppstein eppstein at ics.uci.edu
Wed Jul 25 02:43:48 EDT 2001


In article <9jlo4v$rhbl$1 at sky.inp.nsk.su>,
 "Andy Salnikov" <salnikov at inp.nsk.su> wrote:

> >   int < long < rational < float < complex
> >
>   Just a comment: What bothers me is that floats in computers are not the
> same as R continuum im math. This makes me think that rationals are "better"
> than floats. Indeed, any float number can be exactly represented by
> rational, but not vice virsa.  So my tower would be like that:

The ordering is not by what is a "better" representation, or even by 
information loss, but by what is the most appropriate direction for one-way 
coercions.  Although one could convert float->rational without information 
loss, it would hardly ever be right to do so, because you are just making 
things slower without anything to gain in return: you've already lost your 
exactness and pretending you have it again won't make it so.  On the other 
hand int->long and long->rational are necessary to avoid overflow or 
truncation, and any of these ->float are reasonable to speed up 
computations where it is ok to be approximate.

So I completely agree with Guido's ordering.
-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list