Title: empty specifier for float.__format__ does not always print at least one decimal digit
Type: Stage:
Components: Interpreter Core Versions: Python 3.0, Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: eric.smith
Priority: normal Keywords:

Created on 2008-03-10 11:05 by eric.smith, last changed 2008-03-17 11:02 by eric.smith. This issue is now closed.

Messages (3)
msg63438 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2008-03-10 11:05
PEP 3101 specifies that the empty format presentation type for float
will always print at least one digit after the decimal point, but it
does not do that if the number is output with an exponent:

>>> format(3.0, '')

>>> format(3e200, '')

As currently implemented, the code just maps the empty format specifier
to 'g', and does not add the additional behavior specfied in the PEP.
msg63614 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2008-03-17 03:06
I think the best way to handle this is to add a new format code to
PyOS_ascii_formatd, which implements this behavior.  There can be no
backward compatibility issues, because PyOS_ascii_formatd currently
ensures its format specifier type code is in ['e', 'E', 'f', 'F', 'g',
'G', 'n'].  I'm going to use 'Z' (for lack of a better code) to mean
"implement the default behavior from PEP 3101".
msg63632 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2008-03-17 11:02
Fixed checked in as r61434.
Date User Action Args
2008-03-17 11:02:27eric.smithsetstatus: open -> closed
resolution: fixed
messages: + msg63632
2008-03-17 03:06:53eric.smithsetmessages: + msg63614
2008-03-10 11:05:23eric.smithcreate