[pypy-svn] r9972 - pypy/dist/pypy/lib

tismer at codespeak.net tismer at codespeak.net
Mon Mar 21 00:53:01 CET 2005


Author: tismer
Date: Mon Mar 21 00:53:01 2005
New Revision: 9972

Modified:
   pypy/dist/pypy/lib/struct.py
Log:
0.0 did not work correctly.
test_struct is incomplete and out of date, we are working on it.

Modified: pypy/dist/pypy/lib/struct.py
==============================================================================
--- pypy/dist/pypy/lib/struct.py	(original)
+++ pypy/dist/pypy/lib/struct.py	Mon Mar 21 00:53:01 2005
@@ -34,7 +34,7 @@
  
 The variable struct.error is an exception raised on errors."""
 
-import math,sys
+import math, sys
 
 # TODO: XXX Find a way to get information on native sizes and alignments
 class StructError(Exception):
@@ -60,6 +60,8 @@
     bytes = [ord(b) for b in data[index:index+size]]
     if len(bytes) != size:
         raise StructError,"Not enough data to unpack"
+    if min(bytes) == 0:
+        return 0.0
     if le == 'big':
         bytes.reverse()
     if size == 4:
@@ -126,13 +128,15 @@
     # TODO: XXX Implement checks for floats
     return True
     
-def pack_float(number,size,le):
+def pack_float(number, size, le):
     
     if number < 0:
-        sign=1
+        sign = 1
         number *= -1
+    elif number == 0.0:
+       return "\x00" * size
     else:
-        sign =0
+        sign = 0
     if size == 4:
         bias = 127
         exp = 8
@@ -142,7 +146,7 @@
         exp = 11
         prec = 52
     
-    man,e = math.frexp(number)
+    man, e = math.frexp(number)
     if 0.5 <= man and man < 1.0:
         man *= 2
         e -= 1



More information about the Pypy-commit mailing list