On 1/20/2020 10:59 PM, Karl O. Pinc wrote:
Hello,

There appears to be extremely minimal documentation on how floats are
formatted on output.  All I really see is that float.__str__() is
float.__repr__().  So that means that float->str->float does not
result in a different value.

It would be nice if the output format for float was documented, to the
extent this is possible.  #python suggested that I propose a patch,
but I see no way to write a documentation patch without having any
clue about what Python promises, whether in the CPython implementation
or as part of a specification for Python.

What are the promises Python makes about the str() of a float?  Will
it produce 1.0 today and 1.0e0 or +1.0 tomorrow?  When is the result
in exponential notation and when not?  Does any of this depend on the
underlying OS or hardware or Python implementation?  Etc.
For what it's worth, float's repr internally uses a format of '.17g'. So, format(value, '.17g') will be equal to repr(f), where f is any float.

I think (but don't exactly recall, it's been a while) that you'll get different values if sys.float_repr_style is 'short' or not. I don't know if any current systems don't support 'short'.

I don't know if this is documented. I'm also not sure if this is considered a CPython implementation detail or not, but I would argue that it is.

Eric
_______________________________________________
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/N2O4V4MUG6VYT4HRFRFOIH6NJHVPA6DQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to