overflow definition programming
The condition that occurs when the result of a calculation is too big to store in the intended format. For example, the result of adding one to 255 cannot be represented as an unsigned
, eight-bit integer. In a signed integer representation, overflow can occur when an integer becomes either too positive or too negative.
Overflow can also occur in the exponent of a floating point
number representation. The term "underflow
" is sometimes used for negative overflow of the exponent.
Ignoring overflow will result in nonsensicle results such as 255 + 1 = 0. At the hardware level, the ALU
typically indicates overflow by setting an overflow flag bit which the program can test. Programming languages will typically respond to overflow by raising some kind of signal
or other error condition to halt normal execution.
Some languages attempt to avoid overflow by providing (optional) variable length number representation (multiprecission arithmetic) so that the maximum number representable is limited only by the amount of storage available.