Content deleted Content added
→Origin: Cleaned up maximum representable value list |
T3h 1337 b0y (talk | contribs) →Origin: citing web |
||
Line 3:
In [[computer programming]], an '''integer overflow''' occurs when an [[arithmetic]] operation attempts to create a numeric value that is larger than can be represented within the available storage space. For instance, adding 1 to the largest value that can be represented constitutes an integer overflow. The most common result in these cases is for the least significant representable bits of the result to be stored (the result is said to ''wrap''). On some processors like [[Graphics processing unit|GPU]]s and [[Digital signal processor|DSP]]s, the result [[saturation arithmetic|saturates]]; that is, once the maximum value is reached, attempts to make it larger simply return the maximum result.
==Origin==▼
▲== Origin ==
The [[register width]] of a processor determines the range of values that can be represented. Typical [[Binary numeral system|binary]] register widths include:
Line 12 ⟶ 15:
: 128 bits: maximum representable value 2<sup>128</sup> − 1 = 340,282,366,920,938,463,463,374,607,431,768,211,455
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. {{cite web|url=http://home.comcast.net/~jpittman2/pacman/pacmandossier.html|title=The Pac-Man Dossier|author=Pittman, Jamey}}
A "wrap around" corresponds to the fact, that e.g. if the addition of two positive integers produces an overflow, it may result in a negative number. In counting, one just starts over again from the bottom.
Example: 16 bit signed integer: 30000 + 30000 = −5536.
|