[Python-Dev] Comparing heterogeneous types

Armin Rigo arigo at tunes.org
Thu Jun 17 14:38:06 EDT 2004

Hello Michael,

On Wed, Jun 02, 2004 at 05:18:44PM -0400, Chermside, Michael wrote:
> the long could be less than MAX_FLOAT,
> but still not be precisely representably as a float. In a case
> like this, we really need to convert both to longs and compare
> (or something equivalent) and your code fails to do this.

Is it really what we want?  It seems to me that the precision of a float gives
roughly the magnitude of "uncertainty" of the value that it represents.  If a
float is large enough, then the same float can represent several long integer
values.  It should then probably be considered equal to any of these integers,
instead of just equal to the one arbitrarily returned by casting it to long.

>>> L = 2**60
>>> float(L)
>>> float(L) == float(L+1)

In this situation I would expect this float(L) value to be equal to both L and
L+1.  (But equality between floats is messy anyway.)

A bientot,


More information about the Python-Dev mailing list