Python int overflow

发现一个需要检测溢出的题, 然后发现 Python 的 int 不会溢出, 这下就比较尴尬了.
硬编码一下吧.

if abs(x) > 0x7FFFFFFF:
    return 0

或者我们使用 numpyint32.

import numpy
print(numpy.int32(1+0x7FFFFFFF))
-2147483648

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.