Bugs item #532631, was opened at 2002-03-20 18:34 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=532631&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Tim Peters (tim_one) >Assigned to: Neal Norwitz (nnorwitz) 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: Georg Brandl (gbrandl) Date: 2007-03-10 07:03 Message: Logged In: YES user_id=849994 Originator: NO The docs say, "%f conversions for numbers whose absolute value is over 1e25 are replaced by %g conversions." So is the correct solution "if fabs(x) >= 1e25"? ---------------------------------------------------------------------- Comment By: Tim Peters (tim_one) Date: 2003-01-08 21:28 Message: Logged In: YES user_id=31435 Leaving this unassgned again, with the first and last points unresolved (I don't have time for this now). The "worst case length calc" point is probably fixed. ---------------------------------------------------------------------- Comment By: M.-A. Lemburg (lemburg) Date: 2003-01-08 19: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 01: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 01: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com