[issue28345] 8/3 is calculated incorrectly

Eryk Sun report at bugs.python.org
Mon Oct 3 04:59:25 EDT 2016


Eryk Sun added the comment:

A CPython float uses the platform's double-precision floating point. The significand of a double has 53 bits of precision, which is 15 decimal digits of precision. However, uniquely representing a double in decimal requires 17 digits, which is why the str and repr format is extended with the otherwise insignificant "65" digits. For output, you can format the number with sys.float_info.dig decimal digits. For example:

    >>> sys.float_info.dig
    15
    >>> '%0.*g' % (sys.float_info.dig, 8/3)
    '2.66666666666667'

----------
nosy: +eryksun

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28345>
_______________________________________


More information about the Python-bugs-list mailing list