Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repr() and str() are identical for floats in 3.5 #70429

Closed
andersrundgrennetgmailcom mannequin opened this issue Jan 30, 2016 · 6 comments
Closed

repr() and str() are identical for floats in 3.5 #70429

andersrundgrennetgmailcom mannequin opened this issue Jan 30, 2016 · 6 comments
Labels
docs Documentation in the Doc dir

Comments

@andersrundgrennetgmailcom
Copy link
Mannequin

BPO 26241
Nosy @mdickinson, @ericvsmith, @vadmium, @eryksun

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-01-30.10:31:52.952>
created_at = <Date 2016-01-30.09:22:04.073>
labels = ['invalid', 'docs']
title = 'repr() and str() are identical for floats in 3.5'
updated_at = <Date 2016-01-30.22:33:57.538>
user = 'https://bugs.python.org/andersrundgrennetgmailcom'

bugs.python.org fields:

activity = <Date 2016-01-30.22:33:57.538>
actor = 'eric.smith'
assignee = 'docs@python'
closed = True
closed_date = <Date 2016-01-30.10:31:52.952>
closer = 'mark.dickinson'
components = ['Documentation']
creation = <Date 2016-01-30.09:22:04.073>
creator = 'anders.rundgren.net@gmail.com'
dependencies = []
files = []
hgrepos = []
issue_num = 26241
keywords = []
message_count = 6.0
messages = ['259244', '259246', '259247', '259248', '259249', '259256']
nosy_count = 7.0
nosy_names = ['mark.dickinson', 'eric.smith', 'SilentGhost', 'docs@python', 'martin.panter', 'eryksun', 'anders.rundgren.net@gmail.com']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue26241'
versions = ['Python 3.5']

@andersrundgrennetgmailcom
Copy link
Mannequin Author

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

@andersrundgrennetgmailcom andersrundgrennetgmailcom mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 30, 2016
@SilentGhost
Copy link
Mannequin

SilentGhost mannequin commented Jan 30, 2016

Would you mind linking to the relevant part of documentation?

@vadmium
Copy link
Member

vadmium commented Jan 30, 2016

This discrepancy was supposed to be eliminated in 3.2; see bpo-9337. So assuming you are looking at the right version, it is the documentation that is at fault.

@vadmium vadmium added docs Documentation in the Doc dir and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jan 30, 2016
@eryksun
Copy link
Contributor

eryksun commented Jan 30, 2016

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.

@mdickinson
Copy link
Member

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

@andersrundgrennetgmailcom
Copy link
Mannequin Author

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

3 participants