Integer overflow: Difference between revisions

Content deleted Content added
Restored revision 1227558926 by Zero0000 (talk): Not sure what happened here
top: only integer operations, not floating point
Line 4:
[[File:Odometer rollover.jpg|thumb|250px|Integer overflow can be demonstrated through an [[odometer]] overflowing, a mechanical version of the phenomenon. All digits are set to the maximum 9 and the next increment of the white digit causes a cascade of carry-over additions setting all digits to 0, but there is no higher digit (1,000,000s digit) to change to a 1, so the counter resets to zero. This is ''wrapping'' in contrast to ''saturating''.]]
 
In [[computer programming]], an '''integer overflow''' occurs when an [[arithmetic]] operation on integers attempts to create a numeric value that is outside of the range that can be represented with a given number of digits – either higher than the maximum or lower than the minimum representable value.
 
The most common result of an overflow is that the least significant representable digits of the result are stored; the result is said to ''wrap'' around the maximum (i.e. [[Modular arithmetic|modulo]] a power of the [[radix]], usually two in modern computers, but sometimes ten or other number). On some processors like [[graphics processing unit]]s (GPUs) and [[digital signal processor]]s (DSPs) which support [[saturation arithmetic]], overflowed results would be ''clamped'', i.e. set to the minimum value in the representable range if the result is below the minimum and set to the maximum value in the representable range if the result is above the maximum, rather than wrapped around.