On Mon, Jan 20, 2020 at 09:59:07PM -0600, Karl O. Pinc wrote:

> It would be nice if the output format for float was documented, to the
> extent this is possible.

I don't think we should make any promises about the repr() of floats. 
We've already changed the format at least twice:

- once to switch to the shortest unambiguous representation;
- and once to shift to a more consistent output for NANs.

(NANs on Windows prior to 2.6 used to be displayed as '1.#IND', if I 
recall correctly.)

We may never want to change output format again, but if we document a 
certain format that will be read by people as a guarantee, and that 
closes the door to any change without a long and tedious deprecation 
period.

If anyone wants a guaranteed output format for floats, they ought to use 
the various string formatting operations, which offer guaranteed 
formatting outputs. Or build your own formatter.

I think that the most we should promise is that (with the exception of 
NANs) float -> repr -> float should round-trip with no change in value.


> I don't really care whether there's documentation for __str__() or
> __repr__() or something else.  I'm just thinking that there should be
> some way to guarantee a well defined "useful" float output formatting.

https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting

https://docs.python.org/3/library/string.html#format-string-syntax


-- 
Steven
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/M5NUDXVHCPZNIYXBTNPCGITF4WXNVYHI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to