Mark Dickinson <dicki...@gmail.com> added the comment: Proposed rewrite:
Why are floating point calculations inaccurate? ----------------------------------------------- Users are often surprised by results like this:: >>> 1.2 - 1.0 0.199999999999999996 and think it is a bug in Python. It's not. This has little to do with Python, and much more to do with how the underlying platform handles floating-point numbers. Python floats are stored internally in binary floating-point, using a fixed precision (typically 53 bits). Many numbers that can be written easily in decimal notation (``1.2``, for example), cannot be expressed exactly in this internal binary format. After:: >>> x = 1.2 the value stored for x is a (very good) approximation to the value ``1.2``, but is not exactly equal to it. (On a typical machine, the actual stored value is:: 1.1999999999999999555910790149937383830547332763671875 which is accurate to around 16 decimal digits.) Similarly, the result of any floating-point operation must often be rounded to fit into the internal format, resulting in another tiny error. For a more detailed explanation of what's involved, please see the chapter on :ref:`floating point arithmetic <tut-fp-issues>` in the Python tutorial. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14245> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com