]> granicus.if.org Git - python/commitdiff
decode_long(): Simplified the "is it negative?" test.
authorTim Peters <tim.peters@gmail.com>
Mon, 27 Jan 2003 23:51:11 +0000 (23:51 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 27 Jan 2003 23:51:11 +0000 (23:51 +0000)
Lib/pickletools.py

index 5c0367be0f4e7945d4bd5365955bb646c9d53641..dec533d4928198d17a7dd32ab4cbdcf120877f7f 100644 (file)
@@ -590,14 +590,17 @@ def decode_long(data):
     -256L
     >>> decode_long("\x00\x80")
     -32768L
-    >>> 
+    >>> decode_long("\x80")
+    -128L
+    >>> decode_long("\x7f")
+    127L
     """
     x = 0L
     i = 0L
     for c in data:
         x |= long(ord(c)) << i
         i += 8L
-    if i and (x & (1L << (i-1L))):
+    if data and ord(c) >= 0x80:
         x -= 1L << i
     return x