[Python-bugs-list] [ python-Bugs-454891 ] loss of precision in float marshaling

noreply@sourceforge.net noreply@sourceforge.net
Fri, 24 Aug 2001 01:51:10 -0700


Bugs item #454891, was opened at 2001-08-24 01:51
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=454891&group_id=5470

Category: Parser/Compiler
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: loss of precision in float marshaling

Initial Comment:
putting this in pi.py:

_pi = 3.1415926535897932
class pi:
    def __init__(self):
        self.pi = _pi

then in another module using
import pi
a = pi.pi()

gives 3.1415926535897931  the first time you
run it and 3.1415926535900001 the second time.

What's happened is the first time you run it,
pi.py gets compiled to pi.pyc.  pi.pyc contains
a marshalled version of 3.14159.... .  However,
floats are marshalled to ascii strings with less
than full precision.

Proposed fix: a new floating point marshalling
code should be created, that dumps out the
machine representation of the float in network
byte order and reads it back.  This should be
used in preference to the ascii method on all
platforms using IEEE-754 floats, which is
practically all computers these days.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=454891&group_id=5470