[pypy-svn] r78469 - in pypy/trunk/pypy: objspace/std/test rlib rlib/test

arigo at codespeak.net arigo at codespeak.net
Fri Oct 29 15:11:14 CEST 2010


Author: arigo
Date: Fri Oct 29 15:11:13 2010
New Revision: 78469

Modified:
   pypy/trunk/pypy/objspace/std/test/test_longobject.py
   pypy/trunk/pypy/rlib/rbigint.py
   pypy/trunk/pypy/rlib/test/test_rbigint.py
Log:
-0L == 0L.


Modified: pypy/trunk/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_longobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_longobject.py	Fri Oct 29 15:11:13 2010
@@ -254,3 +254,7 @@
         class myotherlong(long):
             pass
         assert long(myotherlong(21)) == 21L
+
+    def test_negative_zero(self):
+        x = eval("-0L")
+        assert x == 0L

Modified: pypy/trunk/pypy/rlib/rbigint.py
==============================================================================
--- pypy/trunk/pypy/rlib/rbigint.py	(original)
+++ pypy/trunk/pypy/rlib/rbigint.py	Fri Oct 29 15:11:13 2010
@@ -1631,7 +1631,7 @@
             a = _muladd1(a, tens, dig)
             tens = 1
             dig = 0
-    if sign:
+    if sign and a.sign == 1:
         a.sign = -1
     return a
 
@@ -1652,6 +1652,5 @@
         else:
             dig = dig * base + digit
             tens *= base
-    if parser.sign == -1:
-        a.sign = -1
+    a.sign *= parser.sign
     return a

Modified: pypy/trunk/pypy/rlib/test/test_rbigint.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rbigint.py	(original)
+++ pypy/trunk/pypy/rlib/test/test_rbigint.py	Fri Oct 29 15:11:13 2010
@@ -112,6 +112,23 @@
         assert rbigint.fromrarith_int(r_uint(2*sys.maxint+1)).eq(
             rbigint.fromlong(2*sys.maxint+1))
 
+    def test_fromdecimalstr(self):
+        x = rbigint.fromdecimalstr("12345678901234567890523897987")
+        assert x.tolong() == 12345678901234567890523897987L
+        assert x.tobool() is True
+        x = rbigint.fromdecimalstr("+12345678901234567890523897987")
+        assert x.tolong() == 12345678901234567890523897987L
+        assert x.tobool() is True
+        x = rbigint.fromdecimalstr("-12345678901234567890523897987")
+        assert x.tolong() == -12345678901234567890523897987L
+        assert x.tobool() is True
+        x = rbigint.fromdecimalstr("+0")
+        assert x.tolong() == 0
+        assert x.tobool() is False
+        x = rbigint.fromdecimalstr("-0")
+        assert x.tolong() == 0
+        assert x.tobool() is False
+
     def test_add(self):
         x = 123456789123456789000000L
         y = 123858582373821923936744221L
@@ -470,6 +487,11 @@
             num = num * 36 + i
         x = parse_digit_string(Parser(16, -1, range(15,-1,-1)*99))
         assert x.eq(rbigint.fromlong(long('-0x' + 'FEDCBA9876543210'*99, 16)))
+        assert x.tobool() is True
+        x = parse_digit_string(Parser(7, 1, [0, 0, 0]))
+        assert x.tobool() is False
+        x = parse_digit_string(Parser(7, -1, [0, 0, 0]))
+        assert x.tobool() is False
 
 
 BASE = 2 ** SHIFT



More information about the Pypy-commit mailing list