Rounding Bug in Python 2.0! - ugh

Pete Forman gsez020 at kryten.bedford.waii.com
Wed Nov 1 12:40:09 EST 2000


Moshe Zadka writes:
 > On 1 Nov 2000, Pete Forman wrote:
 > 
 > > It would be nice if Python would make use of dtoa() rather than
 > > stock sprintf() to display floating-point numbers.  There are
 > > variants of dtoa in netlib and libg++.
 > 
 > netlib and libg++ aren't always available.
 > Python is meant to be portable...

I meant that the source code based on David Gay's work might be
directly incorporated in the Python implementation.

 > And anyway, the problem isn't necessarily one of display: you have
 > to ways to display floats:
 > 
 > str -- inaccurate but readable
 > repr -- (more) accurate but unreadable

But I want the best of both worlds: readable and accurate :-)

I'd like str() and repr() to manage the following

IEC 60559           Full precision      Desired display
---------           --------------      ---------------
0x4008fbe76c8b4395  3.1229999999999998  3.1229999999999998
0x4008fbe76c8b4396  3.1230000000000002  3.123
0x4008fbe76c8b4397  3.1230000000000007  3.1230000000000007


The criteria that I'm looking to satisfy are:

  1) Round trip - reading a written number should give the same result
  2) Write the minimum number of digits - drop trailing zeros/nines


-- 
Pete Forman                 -./\.- Disclaimer: This post is originated
Western Geophysical           -./\.-  by myself and does not represent
pete.forman at westgeo.com         -./\.-  the opinion of Baker Hughes or
http://www.crosswinds.net/~petef  -./\.-  its divisions.




More information about the Python-list mailing list