On Sun, Jul 13, 2014 at 2:35 AM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > You're not going to hear me arguing that the non-reflexivity of NANs and > SQL NULL is a bad idea, although some very smart people have: > > http://bertrandmeyer.com/2010/02/06/reflexivity-and-other-pillars-of-civilization/ > > Mathematical equality is reflexive. It is fundamental to the nature of > numbers and equality that a number is always equal to itself. To the > degree that floats are supposed to model real numbers, they should obey > the same laws of real numbers. However, they already fail to obey them, > so the failure of reflexivity is just one more problem that makes > floating point such a hard problem. Compared to floating point > arithmetic, calculus is easy. >
And there are plenty of other laws of real numbers that floats violate (or, let's be generous, "approximate to rather than following perfectly"). For instance, adding two positive (non-zero) numbers should result in a number which is greater than either, but thanks to rounding, that's not always true. (Not to mention that "infinity" isn't a number, but it is a floating-point value.) The problem is not equality comparisons, the problem is the expectation that the rules of reals apply to floats. ChrisA -- https://mail.python.org/mailman/listinfo/python-list