Simulating integer overflow in Python

前端 未结 5 1490
無奈伤痛
無奈伤痛 2020-12-06 18:04

Python 2 has two integer datatypes int and long, and automatically converts between them as necessary, especially in order to avoid integer overflo

5条回答
  •  天命终不由人
    2020-12-06 19:06

    I don't know that there's a convenient way to do this natively because it's not normally considered a problem, so it's not something the python devs would want to build in. I think the way you're doing it is fine. You could even subclass the int built-in type and override the __add__(), __sub__(), etc operator methods to include your functionality, but that might be overkill.

提交回复
热议问题