Short-circuit Logic

Ian Kelly ian.g.kelly at gmail.com
Wed May 29 12:50:47 EDT 2013


On Wed, May 29, 2013 at 8:33 AM, rusi <rustompmody at gmail.com> wrote:
> 0.0 == 0.0 implies 5.4 == 5.4
> is not a true statement is what (I think) Steven is saying.
> 0 (or if you prefer 0.0) is special and is treated specially.

It has nothing to do with 0 being special.  A floating point number
will always equal itself (except for nan, which is even more special),
and in particular 5.4 == 5.4.  But if you have two different
calculations that produce 0, or two different calculations that
produce 5.4, you might actually get two different numbers that
approximate 0 or 5.4 thanks to rounding error.  If you then compare
those two ever-so-slightly different numbers, you will find them
unequal.



More information about the Python-list mailing list