On 05/29/2013 12:50 PM, Ian Kelly wrote:
On Wed, May 29, 2013 at 8:33 AM, rusi <rustompm...@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.


Rounding error is just one of the problems. Usually less obvious is quantization error. If you represent a floating number in decimal, but you're using a binary floating point representation, it just might change.

Another error is roundoff error. Even in a pure decimal system of (say) 40 digits, I could type in a 42 digit number and it would get quantized. So just because two 42 digit numbers are different doesn't imply that the 40 digit internal format would be.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to