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.

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

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

Messages (6)
msg259244 - (view) Author: Anders Rundgren ( 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].

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 ( Date: 2016-01-30 14:23
Apparently the docs have changed since 2.7:

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 :-)

Date User Action Args
2022-04-11 14:58:27adminsetgithub: 70429
2016-01-30 22:33:57eric.smithsetnosy: + eric.smith
2016-01-30 + 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