]> granicus.if.org Git - python/commitdiff
On 64 bit systems, int literals that use less than 64 bits are now ints
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 9 Jul 2006 22:14:42 +0000 (22:14 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 9 Jul 2006 22:14:42 +0000 (22:14 +0000)
rather than longs.  This also fixes the test for eval(-sys.maxint - 1).

Lib/test/test_compile.py
Misc/NEWS
Python/mystrtoul.c

index bacec35766c05c29746c4a53e4c51e8a9cf4c74d..688a02dd56c23f06172427a4d716e8ed3a2901f7 100644 (file)
@@ -216,6 +216,21 @@ if 1:
         self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int))
         self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), long))
 
+    if sys.maxint == 9223372036854775807:
+        def test_32_63_bit_values(self):
+            a = +4294967296  # 1 << 32
+            b = -4294967296  # 1 << 32
+            c = +281474976710656  # 1 << 48
+            d = -281474976710656  # 1 << 48
+            e = +4611686018427387904  # 1 << 62
+            f = -4611686018427387904  # 1 << 62
+            g = +9223372036854775807  # 1 << 63 - 1
+            h = -9223372036854775807  # 1 << 63 - 1
+
+            for variable in self.test_32_63_bit_values.func_code.co_consts:
+                if variable is not None:
+                    self.assertTrue(isinstance(variable, int))
+
     def test_sequence_unpacking_error(self):
         # Verify sequence packing/unpacking with "or".  SF bug #757818
         i,j = (1, -1) or (-1, 1)
index bc34360ab7ab16489850a647c1159611ddf536d9..ff336c62aca9dc3437ef9b71a09b33960246030e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -30,6 +30,9 @@ Core and builtins
 
 - Bug #1519018: 'as' is now validated properly in import statements.
 
+- On 64 bit systems, int literals that use less than 64 bits are
+  now ints rather than longs.
+
 Library
 -------
 
index 1fc360be95a93cbe0255ecf0e030b44603d88157..51553fbe1f34e8c49e81d3a1d31b0cc41f80ca06 100644 (file)
@@ -69,11 +69,22 @@ static unsigned long smallmax[] = {
  * calculated by [int(math.floor(math.log(2**32, i))) for i in range(2, 37)].
  * Note that this is pessimistic if sizeof(long) > 4.
  */
+#if SIZEOF_LONG == 4
 static int digitlimit[] = {
        0,  0, 32, 20, 16, 13, 12, 11, 10, 10,  /*  0 -  9 */
        9,  9,  8,  8,  8,  8,  8,  7,  7,  7,  /* 10 - 19 */
        7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  /* 20 - 29 */
        6,  6,  6,  6,  6,  6,  6};             /* 30 - 36 */
+#elif SIZEOF_LONG == 8
+/* [int(math.floor(math.log(2**64, i))) for i in range(2, 37)] */
+static int digitlimit[] = {
+        0,   0, 64, 40, 32, 27, 24, 22, 21, 20,  /*  0 -  9 */
+       19,  18, 17, 17, 16, 16, 16, 15, 15, 15,  /* 10 - 19 */
+       14,  14, 14, 14, 13, 13, 13, 13, 13, 13,  /* 20 - 29 */
+       13,  12, 12, 12, 12, 12, 12};             /* 30 - 36 */
+#else
+#error "Need table for SIZEOF_LONG"
+#endif
 
 /*
 **     strtoul