Python int overflow
Jan 16, 2017
Python int overflow
发现一个需要检测溢出的题, 然后发现 Python 的 int 不会溢出, 这下就比较尴尬了.
硬编码一下吧.
if abs(x) > 0x7FFFFFFF:
return 0
或者我们使用 numpy
的 int32
.
import numpy
print(numpy.int32(1+0x7FFFFFFF))
-2147483648
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.