Author tim.peters
Recipients christian.heimes, gvanrossum, noam, tim.peters
Date 2007-12-11.01:58:11
SpamBayes Score 0.00200733
Marked as misclassified No
Message-id <1197338294.13.0.775077871936.issue1580@psf.upfronthosting.co.za>
In-reply-to
Content
There is nothing you can do to repr() that's sufficient by itself to
ensure eval(repr(x)) == x.

The other necessary part is correctly rounded float /input/ routines.

The 754 standard does not require correctly rounding input or output
routines.  It does require that eval(repr(x)) == x provided that repr(x)
produce at least 17 significant digits (not necessarily correctly
rounded, but "good enough" so that eval(repr(x)) == x).  That's why
Python produces 17 significant digits.  While there's no guarantee that
all platform I/O routines are good enough to meet the 754 requirement,
most do, and what Python's repr() actually does is the strongest that
/can/ be done assuming no more than full 754 conformance.

Again, this cannot be improved cross-platform without Python supplying
both output and input routines.  Burger's output routines supply only
half of what's needed.  An efficient way to do the other half (correctly
rounding input) was first written up by Clinger.  Note that neither the
Burger/Dybvig output code nor the Clinger input code are used much in
practice anymore; David Gay's code is usually used instead for "go fast"
reasons:

http://mail.python.org/pipermail/python-list/2004-July/272167.html

Clinger also endorses Gay's code:

ftp://ftp.ccs.neu.edu/pub/people/will/retrospective.pdf

However, as the Python list link says, Gay's code is "mind-numbingly
complicated".

There is no easy cross-platform solution, where "cross-platform" means
just "limited to 754 platforms".
History
Date User Action Args
2007-12-11 01:58:14tim.peterssetspambayes_score: 0.00200733 -> 0.00200733
recipients: + tim.peters, gvanrossum, christian.heimes, noam
2007-12-11 01:58:14tim.peterssetspambayes_score: 0.00200733 -> 0.00200733
messageid: <1197338294.13.0.775077871936.issue1580@psf.upfronthosting.co.za>
2007-12-11 01:58:14tim.peterslinkissue1580 messages
2007-12-11 01:58:12tim.peterscreate