Floating point (in)accuracy?

Gregor Hoffleit gregor at mediasupervision.de
Wed Apr 25 11:52:55 EDT 2001


On Wed, Apr 25, 2001 at 03:33:55PM +0000, Dinu Gherman wrote:
> Apparently the python mailiing lists on python.org are blocked, so let
> 
> me ask here. Is there any good reason for the following behaviour to 
> be different on Python 1.5.2 and 2.0?

>From Andrew Kuchling's 'What's new in Python 2.0'
(http://www.python.org/2.0/new-python.html):

  "Taking the repr() of a float now uses a different formatting precision
  than str(). repr() uses %.17g format string for C's sprintf(), while str()
  uses %.12g as before. The effect is that repr() may occasionally show more
  decimal places than str(), for certain numbers. For example, the number 8.1
  can't be represented exactly in binary, so repr(8.1) is
  '8.0999999999999996', while str(8.1) is '8.1'."

  
    Gregor
    




More information about the Python-list mailing list