On Wed, 17 Mar 2010 12:27:01 pm Raymond Hettinger wrote: > On Mar 16, 2010, at 3:16 PM, Greg Ewing wrote: > > Seems to me that this education would mostly consist of saying > > "don't compare floats and decimals", which is why I think that > > disallowing them in the first place would be better. > > That makes sense. > > I do worry that 2.x currently does make the comparison > and gives the wrong answer. We have the ability to > make it a correct answer. But, it seems like the mood > here is that wrong-is-better-than-right for an action > that someone shouldn't be doing in the first place.
I don't get this. Why is it "wrong" to compare Decimals to floats, and why shouldn't I do so? What harm is there? If the argument is that naive users who don't understand floats may be confused by the results, then the problem lies with floats, and if you really want to avoid confusing the float-naive, then we should prohibit all comparisons on floats: >>> 1e20 + 1e4 < 1e20 + 2e4 False I don't mean that as a serious suggestion -- it would be absurd to cripple floats for the sake of avoiding confusion of those who don't understand floats. Why are Decimals different? I can't see why comparing Decimal(1) to float(1) is wrong in any sense. I can see that comparing Decimal("1.1") to float("1.1") may confuse the float-naive, but the float naive will be confused by this too: >>> x = 1.0/3 >>> x + 1.0 - 1.0 == x False There's an awful lot about floats that is confusing to naive users, I don't see that the behaviour of Decimals will make it worse. -- Steven D'Aprano _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com