[pypy-svn] r75983 - in pypy/branch/fast-forward/pypy: objspace/std rlib/rstruct
benjamin at codespeak.net
benjamin at codespeak.net
Wed Jul 7 17:23:37 CEST 2010
Author: benjamin
Date: Wed Jul 7 17:23:36 2010
New Revision: 75983
Modified:
pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py
pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
Log:
fix struct float/double ops
Modified: pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py Wed Jul 7 17:23:36 2010
@@ -169,11 +169,11 @@
def pack_float(f):
result = []
- ieee.pack_float8(result, f)
+ ieee.pack_float(result, f, 8, False)
return ''.join(result)
def unpack_float(s):
- return ieee.unpack_float8(s)
+ return ieee.unpack_float(s, False)
def marshal_w__Float(space, w_float, m):
if m.version > 1:
Modified: pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py (original)
+++ pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py Wed Jul 7 17:23:36 2010
@@ -123,14 +123,17 @@
return ((sign << BITS - 1) | (exp << MANT_DIG - 1)) | mant
-def pack_float8(result, x):
- unsigned = float_pack(x, 8)
- for i in range(8):
+def pack_float(result, x, size, be):
+ unsigned = float_pack(x, size)
+ for i in range(size):
result.append(chr((unsigned >> (i * 8)) & 0xFF))
+ if be:
+ result.reverse()
-def unpack_float8(s):
+def unpack_float(s, be):
unsigned = 0
- for i in range(8):
- unsigned |= ord(s[i]) << (i * 8)
- return float_unpack(unsigned, 8)
+ for i in range(len(s)):
+ c = ord(s[len(s) - 1 - i if be else i])
+ unsigned |= c << (i * 8)
+ return float_unpack(unsigned, len(s))
More information about the Pypy-commit
mailing list