Python 2.4 does not marshal infinity floating point properly under Win32

Pierre Rouleau prouleau001 at gmail.com
Thu Nov 30 21:17:35 CET 2006


Hi all,

When using Python 2.4.x on a Win32 box,
marshal.loads(marshal.dumps(1e66666))  returns 1.0 instead of infinity
as it should and does under Python 2.5 (also running on Win32 ).

This problem was reported in another thread here by Peter Hansen
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/5c2b4b2a88c8df4/f216739705c9304f?lnk=gst&q=simplejson&rnum=5#f216739705c9304f

Is this considered an important enough bug to fix it in Python 2.4?



The following script exercise the problem when executed::

#---------------------------test_marshal.py--------------------------------------------------
import marshal

INFINITY = 1e66666
inf = 1e300 * 1e300
nan = inf - inf


def show(title, msg):
   print '%-10s : ' % title,
   msg2 = ''
   count = 0
   for chr in msg:
       count += 1
       val = ord(chr)
       print hex(val),
       if 31 < val < 128:
           msg2 += chr
       else:
           msg2 += '.'
   print '     ' * (9-count), ' : ', msg2



show('Nan', marshal.dumps(nan))
show('Infinity', marshal.dumps(INFINITY))
show('Infinity', marshal.dumps(inf))
show('Infinity', marshal.dumps(1e666))

val = marshal.loads(marshal.dumps(1e666))
print val
val = marshal.loads(marshal.dumps(INFINITY))
print val
assert val==INFINITY
#-------------------------------------------------------------------------------------------------------



When running the script on Win32 box with Python 2.4.3 or 2.4.4 I get::

D:\dev\python\test>t_marshal
Nan        :  0x66 0x7 0x2d 0x31 0x2e 0x23 0x49 0x4e 0x44   :
f.-1.#IND
Infinity   :  0x66 0x6 0x31 0x2e 0x23 0x49 0x4e 0x46        :  f.1.#INF
Infinity   :  0x66 0x6 0x31 0x2e 0x23 0x49 0x4e 0x46        :  f.1.#INF
Infinity   :  0x66 0x6 0x31 0x2e 0x23 0x49 0x4e 0x46        :  f.1.#INF
1.0
1.0
Traceback (most recent call last):
 File "D:\dev\python\test\t_marshal.py", line 33, in ?
   assert val==INFINITY
AssertionError

But when running the same script on a Win32 box, using Python 2.5, I
get::

C:\dev\python\test>t_marshal
Nan        :  0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf8 0xff   :  g........
Infinity   :  0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf0 0x7f   :  g.......¦
Infinity   :  0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf0 0x7f   :  g.......¦
Infinity   :  0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf0 0x7f   :  g.......¦
1.#INF
1.#INF


#-------------------------------------------------



--

Pierre Rouleau




More information about the Python-list mailing list