[Python-Dev] Comparing heterogeneous types
Guido van Rossum
guido at python.org
Wed Jun 23 01:49:51 EDT 2004
> I maintain that when comparing a long with a float
> where the exponent is larger than the precision, that the
> float should be treated as if it were EXACTLY EQUAL TO
> <coefficient>*2^<exponent>, instead of trying to treat it as
> some sort of a range. Similarly, if we implemented a Rational
> type, I would suggest that instances of float (or of Facundo's
> Decimal) where <exponent> is LESS than the digits of
> <coefficient> should be treated as if they were EXACTLY EQUAL
> TO the corresponding fraction-over-a-power-of-two.
Right. I'm an amateur in this field too, but I've now been convinced
many times over this is what comparisons *should* do, rather than
converting the long (or int) to float and doing the comparison as
float (what they currenttly do). Anyone feel like implementing this
for 2.4? (Andrew Koenig posted an algorithm here a few weeks or so
ago.)
(For other operations, I still want to see e.g. long+float to return a
float rather than a long -- you *have* to do it this way for obvious
reasons when the values are relatively small, e.g. consider 1 + 0.5.)
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list