[Python-bugs-list] [ python-Bugs-532631 ] Confusions in formatfloat

SourceForge.net noreply@sourceforge.net
Wed, 08 Jan 2003 11:55:04 -0800


Bugs item #532631, was opened at 2002-03-20 19:34
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=532631&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Tim Peters (tim_one)
>Assigned to: Tim Peters (tim_one)
Summary: Confusions in formatfloat

Initial Comment:
stringobject.c's formatfloat seems confused in a 
couple respects.

1. Testing "fabs(x)/1e25 >= 1e25" is pretty baffling.  
What is it intending to do?  If it means what it says, 
it should be the simpler "fabs(x) >= 1e50".  But maybe 
it really intended to test "fabs(x) >= 1e25".

2. The "worst case length calc" is fantasy in some %f 
cases.  It assumes there's one digit before the 
decimal point, but, e.g., '%.100f'% 1e49 produces 
dozens of digits before the decimal point.  We're 
saved from a buffer overrun thanks to the PyOS_snprintf
() following, but unclear that truncation is sensible 
here (e.g., the user asked for a precision of 100 
here, but only gets back 50 digits after the decimal 
point).

Complication:  we're deliberately replacing C's %f 
with C's %g in some cases, but the docs don't document 
the rules Python intends for %f.

----------------------------------------------------------------------

>Comment By: M.-A. Lemburg (lemburg)
Date: 2003-01-08 20:55

Message:
Logged In: YES 
user_id=38388

Your first finding is baffling indeed. No idea how it came
to be 
(I don't remember having added such code). The test seems to
be intended to switch from 'g' format to 'f' format at an
arbirary number of decimals before the decimal point. 
"fabs(x) >= 1e50" should do the same. Feel free to change
this.

The second point should be fixed after my checkin:
>>> '%.100f'% 1e49
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: formatted float is too long (precision too
large?)


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-01-08 02:29

Message:
Logged In: YES 
user_id=31435

Marc-Andre is in a better position to tell us what he fixed 
than I am, so assigned to him.  MAL, feel free to close this if 
you think it's history.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-08 02:24

Message:
Logged In: YES 
user_id=33168

Tim, did MALs recent checkin fix any of these problems?  Is
doc the only thing left to do?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=532631&group_id=5470