37 lines
1.5 KiB
Diff
37 lines
1.5 KiB
Diff
diff --git a/src/sage/arith/long.pxd b/src/sage/arith/long.pxd
|
|
index 1c9a53387a0..d96b98f247c 100644
|
|
--- a/src/sage/arith/long.pxd
|
|
+++ b/src/sage/arith/long.pxd
|
|
@@ -270,6 +270,17 @@ cdef inline bint integer_check_long_py(x, long* value, int* err):
|
|
sage: L += [-x for x in L] + [0, long_min()]
|
|
sage: for v in L:
|
|
....: assert check_long_py(int(v)) == v
|
|
+ sage: check_long_py(int(2^60))
|
|
+ 1152921504606846976 # 64-bit
|
|
+ 'Overflow (...)' # 32-bit
|
|
+ sage: check_long_py(int(2^61))
|
|
+ 2305843009213693952 # 64-bit
|
|
+ 'Overflow (...)' # 32-bit
|
|
+ sage: check_long_py(int(2^62))
|
|
+ 4611686018427387904 # 64-bit
|
|
+ 'Overflow (...)' # 32-bit
|
|
+ sage: check_long_py(int(2^63))
|
|
+ 'Overflow (...)'
|
|
sage: check_long_py(int(2^100))
|
|
'Overflow (...)'
|
|
sage: check_long_py(int(long_max() + 1))
|
|
@@ -309,7 +320,12 @@ cdef inline bint integer_check_long_py(x, long* value, int* err):
|
|
|
|
cdef long lead
|
|
cdef long lead_2_overflow = (<long>1) << (BITS_IN_LONG - PyLong_SHIFT)
|
|
- cdef long lead_3_overflow = (<long>1) << (BITS_IN_LONG - 2 * PyLong_SHIFT)
|
|
+ cdef long lead_3_overflow
|
|
+ if BITS_IN_LONG < 2 * PyLong_SHIFT:
|
|
+ # in this case 3 digit is always overflow
|
|
+ lead_3_overflow = 0
|
|
+ else:
|
|
+ lead_3_overflow = (<long>1) << (BITS_IN_LONG - 2 * PyLong_SHIFT)
|
|
if size == 0:
|
|
value[0] = 0
|
|
err[0] = 0
|