Integer overflow: Difference between revisions

Content deleted Content added
add Python as example with native mp support.
changed example to prevent confusion since signed overflow is undefined in C.
Line 14:
 
Since an arithmetic operation may produce a result larger than the maximum representable value, a potential error condition may result. In the [[C (programming language)|C programming language]], signed integer overflow causes [[undefined behavior]], while unsigned integer overflow causes the number to be reduced [[modular arithmetic|modulo a power of two]], meaning that unsigned integers "wrap around" on overflow. This "wrap around" is the cause of the famous "[[kill screen|Split Screen]]" in Pac-Man.<ref>{{cite web|url=http://home.comcast.net/~jpittman2/pacman/pacmandossier.html|title=The Pac-Man Dossier|author=Pittman, Jamey}}</ref>
A "wrap around" corresponds to the fact, that e.g. if the addition of two positive integers produces an overflow, it may result in aan negativeunexpected numberresult. InFor counting,example onewith justunsigned starts32 bit integers, over4000000000u again+ from1000000000u the= bottom705032704u.
Example: 16 bit signed integer: 30000 + 30000 = −5536.
 
<!-- Diagram that illustrates wrapping behavior of integer representation. -->