[issue16609] random.random() / float() loses precision when passed to str()

R. David Murray report at bugs.python.org
Tue Dec 4 21:00:29 CET 2012


R. David Murray added the comment:

In fact it has been changed.  In Python3 you get:

>>> x = 0.88022393777095409
>>> x
0.8802239377709541
>>> str(x)
'0.8802239377709541'

Even in 2.7 you would get the above repr, not the one you showed.  This is because 2.7 and 3.3 use the "shortest repr" described in the floating point document, but 2.7 still uses the old rounding as the default str representation (for backward compatibility reasons).

While you could still make an argument for updating the 2.7 docs, I'm not sure it is worth it.  If you (or anyone) want to propose a patch, I would suggest that instead of adding a note to the random docs, that a glossary entry be added for 'floating point' which mentions it as a 2.7 limitation, and a link to that glossary entry from the random docs.

----------
assignee:  -> docs at python
components: +Documentation -Interpreter Core
nosy: +docs at python, r.david.murray
priority: normal -> low
type:  -> behavior

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


More information about the Python-bugs-list mailing list