[pypy-svn] r32385 - pypy/dist/pypy/objspace/std
arigo at codespeak.net
arigo at codespeak.net
Sat Sep 16 14:01:19 CEST 2006
Author: arigo
Date: Sat Sep 16 14:01:18 2006
New Revision: 32385
Modified:
pypy/dist/pypy/objspace/std/longobject.py
Log:
Simplification and comments.
Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py (original)
+++ pypy/dist/pypy/objspace/std/longobject.py Sat Sep 16 14:01:18 2006
@@ -625,12 +625,18 @@
digits_from_nonneg_long._annspecialcase_ = "specialize:argtype(0)"
def digits_for_most_neg_long(l):
+ # This helper only works if 'l' is the most negative integer of its
+ # type, which in base 2 looks like: 1000000..0000
digits = []
while (intmask(l) & MASK) == 0:
digits.append(0)
l = l >> SHIFT
- l = intmask(l)
- digits.append(((l^(l-1))+1) >> 1)
+ # now 'l' looks like: ...111100000
+ # turn it into: ...000100000
+ # to drop the extra unwanted 1's introduced by the signed right shift
+ l = -intmask(l)
+ assert l >= 0
+ digits.append(l)
return digits
digits_for_most_neg_long._annspecialcase_ = "specialize:argtype(0)"
More information about the Pypy-commit
mailing list