[Tutor] How does the interpreter determine how many decimal places to display for a float?
Peter Otten
__peter__ at web.de
Sat May 15 04:37:21 EDT 2021
On 15/05/2021 05:29, boB Stepp wrote:
> How does >= Python 3.1 determine the "shortest of these"?
This is an interesting question...
A little digging in the Python source turns up
https://github.com/python/cpython/blob/main/Python/dtoa.c
Does that answer your question? Well, it didn't help me, so I looked for
the original code and found what seems to be the corresponding paper
David M. Gay:
Correctly Rounded Binary-Decimal and Decimal-Binary Conversion
https://ampl.com/REFS/rounding.pdf
which in turn leads to
Guy L. Steele Jr., Jon L White:
How to Print Floating-Point Numbers Accurately
https://lists.nongnu.org/archive/html/gcl-devel/2012-10/pdfkieTlklRzN.pdf
Hope that helps ;)
More information about the Tutor
mailing list