Incomparable abominations (was: python-dev Summary)
Andrew Koenig
ark at research.att.com
Wed Mar 19 17:18:57 EST 2003
David> I completely DO NOT BUY Guido's point in the thread. The
David> failure of The argument is sometimes made that it is a
David> programming mistake to try to compare items of incomensurable
David> types.
Actually, the problem is somewhat worse than that, because at present,
comparison between long integers and floating-point numbers is done by
converting the integer to floating-point and comparing the converted
result. One problem with this approach is that the conversion might
fail. So, for example, [0.0,1L<<10000].sort() typically causes a
run-time error.
More subtle problems can occur because of loss of information in
conversions. For example:
>>> x = 10000000000000000000000000000000000
>>> y = x+1
>>> z = float(x)
>>> x == z
1
>>> y == z
1
>>> x == y
0
See SF bug report #513866 for more detail.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list