Issue 26241: repr() and str() are identical for floats in 3.5
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) * ![]() |
Date: 2016-01-30 09:33 | |
Would you mind linking to the relevant part of documentation? |
|||
| msg259247 - (view) | Author: Martin Panter (martin.panter) * ![]() |
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) * ![]() |
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) * ![]() |
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:27 | admin | set | github: 70429 |
| 2016-01-30 22:33:57 | eric.smith | set | nosy:
+ eric.smith |
| 2016-01-30 14:23:19 | anders.rundgren.net@gmail.com | set | messages: + msg259256 |
| 2016-01-30 10:31:52 | mark.dickinson | set | status: open -> closed resolution: not a bug messages: + msg259249 stage: resolved |
| 2016-01-30 10:19:32 | mark.dickinson | set | nosy:
+ mark.dickinson |
| 2016-01-30 09:58:55 | eryksun | set | nosy:
+ eryksun messages: + msg259248 |
| 2016-01-30 09:43:12 | martin.panter | set | nosy:
+ docs@python, martin.panter messages: + msg259247 assignee: docs@python |
| 2016-01-30 09:33:35 | SilentGhost | set | nosy:
+ SilentGhost messages: + msg259246 |
| 2016-01-30 09:22:04 | anders.rundgren.net@gmail.com | create | |

