Python 2 has two integer datatypes int and long, and automatically converts between them as necessary, especially in order to avoid integer overflow.
I am simulating a C function in Python and am wondering if there are standard ways to re-enable integer overflow. For the nonce, I’ve used
overflow_point = maxint + 1
if value > overflow_point:
value -= 2 * overflow_point
Is there a more standard way to do the same thing?
I think the basic idea is sound, but needs some tweaks:
sys.maxint+1, but it should;sys.maxintcan be exceeded several times over as a result of a single operation;-sys.maxint-1also need to be considered.With this in mind, I came up with the following: