Next: , Previous: , Up: Arithmetic   [Contents][Index]

6.3 Integer Overflow

When the mathematical value of an arithmetic operation doesn’t fit in the range of the data type in use, that’s called overflow. When it happens in integer arithmetic, it is integer overflow.

Integer overflow happens only in arithmetic operations. Type conversion operations, by definition, do not cause overflow, not even when the result can’t fit in its new type. See Integer Conversion.

Signed numbers use two’s-complement representation, in which the most negative number lacks a positive counterpart (see Integers in Depth). Thus, the unary ‘-’ operator on a signed integer can overflow.