This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: repr() and str() are identical for floats in 3.5
Type: Stage: resolved
Components: Documentation Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: SilentGhost, anders.rundgren.net@gmail.com, docs@python, eric.smith, eryksun, mark.dickinson, martin.panter
Priority: normal Keywords:

Created on 2016-01-30 09:22 by anders.rundgren.net@gmail.com, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg259244 - (view) Author: Anders Rundgren (anders.rundgren.net@gmail.com) Date: 2016-01-30 09:22
According to the documentation repr() and str() are different when it comes to number formatting.  A test with a 100 million random and selected IEEE 64-bit values returned no differences
msg259246 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-01-30 09:33
Would you mind linking to the relevant part of documentation?
msg259247 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-30 09:43
This discrepancy was supposed to be eliminated in 3.2; see Issue 9337. So assuming you are looking at the right version, it is the documentation that is at fault.
msg259248 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-01-30 09:58
> A test with a 100 million random and selected IEEE 64-bit values 
> returned no differences

The float type's tp_str and tp_repr both call float_repr in Objects/floatobject.c. See the 3.5.1 PyFloat_Type definition [1].

Perhaps you were reading something in reference to Python 2, which has separate float_str and float_repr functions. See the 2.7.11 PyFloat_Type definition [2] and the header file where PyFloat_STR_PRECISION is defined to be 12 digits [3].

[1]: https://hg.python.org/cpython/file/v3.5.1/Objects/floatobject.c#l1839
[2]: https://hg.python.org/cpython/file/v2.7.11/Objects/floatobject.c#l2118
[3]: https://hg.python.org/cpython/file/v2.7.11/Include/floatobject.h#l24
msg259249 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2016-01-30 10:31
Closing: as Martin pointed out, the behaviour is intentional, and without a reference to a particular part of the documentation this issue isn't useful. (Anders: if you find a part of the 3.5 documentation that does state that str and repr are different for floats, please feel free to re-open and link to that section of the documentation so that it can be fixed.)
msg259256 - (view) Author: Anders Rundgren (anders.rundgren.net@gmail.com) Date: 2016-01-30 14:23
Apparently the docs have changed since 2.7:
https://docs.python.org/3.5/tutorial/floatingpoint.html

However, the documentation still "sort of" mentions repr() as the most accurate form which isn't entirely correct since it nowadays is identical to str() for floats.

No big deal, I just thought I was doing something wrong :-)

related: http://bugs.python.org/issue26229
History
Date User Action Args
2022-04-11 14:58:27adminsetgithub: 70429
2016-01-30 22:33:57eric.smithsetnosy: + eric.smith
2016-01-30 14:23:19anders.rundgren.net@gmail.comsetmessages: + msg259256
2016-01-30 10:31:52mark.dickinsonsetstatus: open -> closed
resolution: not a bug
messages: + msg259249

stage: resolved
2016-01-30 10:19:32mark.dickinsonsetnosy: + mark.dickinson
2016-01-30 09:58:55eryksunsetnosy: + eryksun
messages: + msg259248
2016-01-30 09:43:12martin.pantersetnosy: + docs@python, martin.panter
messages: + msg259247

assignee: docs@python
components: + Documentation, - Interpreter Core
2016-01-30 09:33:35SilentGhostsetnosy: + SilentGhost
messages: + msg259246
2016-01-30 09:22:04anders.rundgren.net@gmail.comcreate