On Tuesday, May 28, 2013 2:10:05 AM UTC+2, Nobody wrote: > On Mon, 27 May 2013 13:11:28 -0700, Ahmed Abdulshafy wrote: > > > > > On Sunday, May 26, 2013 2:13:47 PM UTC+2, Steven D'Aprano wrote: > > > > > >> What the above actually tests for is whether x is so small that (1.0+x) > > >> cannot be distinguished from 1.0, which is not the same thing. It is > > >> also quite arbitrary. Why 1.0? Why not (0.0001+x)? Or (0.00000001+x)? > > >> Or (10000.0+x)? > > > > > > That may be true for integers, > > > > What may be true for integers? > > > > > but for floats, testing for equality is not always precise > > > > And your point is? > > > > What Steven wrote is entirely correct: sys.float_info.epsilon is the > > smallest value x such that 1.0 and 1.0+x have distinct floating-point > > representations. It has no relevance for comparing to zero.
He just said that the way to test for zero equality is x == 0, and I meant that this is true for integers but not necessarily for floats. And that's not specific to Python. -- http://mail.python.org/mailman/listinfo/python-list