[Python-bugs-list] fpformat (PR#74)

guido@CNRI.Reston.VA.US guido@CNRI.Reston.VA.US
Fri, 10 Sep 1999 10:34:13 -0400 (EDT)


> I'm new to Python, so maybe no one really uses fpformat, but I
> needed a scientific notation formatted string. When fpformat.sci()
> is passed an arg ALREADY in sci notation of the usual format, it
> produces either a correct answer, an incorrect answer, or raises an
> exception, depending on the absolute value of the exponent. The
> exponent is picked out and passed to eval(), but if the exponent has
> a leading zero, eval() will attempt to interpret the exponent as an
> octal number. Thus '1.23e005' and '1.23e-007' are interpreted
> correctly, '1.23e010' and '1.23e-017' are interpreted incorrectly
> (as 1.23e8 and 1.23e-15), and '1.23e-008' and '1.23e019' bomb.

> My work-around is not to pass in anything already in scientific notation.

Thanks for reporting this!  There's a simple fix (which I'll check
into the CVS source tree momentarily) -- change the eval() call to
int().

I guess fpformat is mostly obsolete (the library docs for it say so)
because you can use things like "%10.6e" % x; the only use I see for
sci() is if you always want a 3-digit exponent.  Is this essential for 
you?

--Guido van Rossum (home page: http://www.python.org/~guido/)