Verified:

Xinhuan Game profile

Member
3728

Jan 19th 2013, 6:00:55

Yes Lymz.

As an example, a 1-byte integer's range is -128 to +127 (that is, 1 byte has 8 bits, which can represent 2^8 = 256 integers, including the integer 0).

If you have 120 units, and 50 more returned from the market, you would now have 170 units, but it wraps around to -86 jets (just deduct 256 from 170). This is called addition overflow.

Overflow can also occur in the negative end (No, it is not called underflow, Underflow is completely different and refers to the loss of precision when you add a large number to a small number and the result is no difference to the large number because the large number doesn't have enough significant digits.)


The checks to prevent this from happening obviously is to check if the 120+50 results in a number that is less than the original amount of 120, but you have to do this for every single thing in the game (every unit, cash amount, pci amount, food amount, tech amount, etc), and the code gets very convoluted quickly.


Edited By: Xinhuan on Jan 19th 2013, 6:04:51
Back To Thread
See Original Post