classification
Title: Remove implicit '%f' -> '%g' switch from float formatting.
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.1
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: eric.smith, mark.dickinson
Priority: high Keywords: patch

Created on 2009-04-27 20:50 by mark.dickinson, last changed 2009-05-01 15:38 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
issue5859_stage1.patch mark.dickinson, 2009-05-01 10:37 patch to dynamically allocate buffers for float formatting
issue5859_stage2.patch mark.dickinson, 2009-05-01 13:15
Messages (6)
msg86693 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-04-27 20:50
Currently, Python switches from %f to %g formatting at 1e50.  This 
applies both to the old-style percent formatting, and to the newer PEP 
3101-style formatting:

>>> '%f' % 2.**166
'93536104789177786765035829293842113257979682750464.000000'
>>> '%f' % 2.**167
'1.87072e+50'

>>> format(2.**166, 'f')
'93536104789177786765035829293842113257979682750464.000000'
>>> format(2.**167, 'f')
'1.87072e+50'

The main reason for the switch seems to have been implementation 
convenience:  it makes it possible to use a fixed-size buffer in
the float formatting routines.

I propose removing this feature for Python 3.1, but leaving it in place 
for 2.7.

See

http://mail.python.org/pipermail/python-dev/2009-April/089030.html

for additional discussion.
msg86878 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-01 10:37
Here's a patch which doesn't fix the '%f' -> '%g' switch, but paves the
way for that switch by getting rid of the fixed-size buffers in
formatfloat in unicodeobject.c, and in the fallback version of
PyOS_double_to_string.
msg86881 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-01 11:43
No new test failures on Linux or OS X, with or without the fallback code.  
I've committed this in r72161.
msg86882 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-05-01 12:04
The patch looks good to me.
msg86884 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-01 13:15
Here's the patch that actually removes the %f -> %g switch.
msg86886 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-01 15:37
Fixed in r72165.
History
Date User Action Args
2009-05-01 15:38:00mark.dickinsonsetstatus: open -> closed
resolution: accepted
messages: + msg86886
2009-05-01 13:15:38mark.dickinsonsetfiles: + issue5859_stage2.patch

messages: + msg86884
2009-05-01 12:04:36eric.smithsetmessages: + msg86882
2009-05-01 11:43:31mark.dickinsonsetmessages: + msg86881
2009-05-01 10:50:34mark.dickinsonsetstage: needs patch -> patch review
2009-05-01 10:37:45mark.dickinsonsetfiles: + issue5859_stage1.patch
keywords: + patch
messages: + msg86878
2009-04-27 20:50:03mark.dickinsoncreate