Jump to content

Arithmetic overflow: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
Poohneat (talk | contribs)
mNo edit summary
Line 8: Line 8:
# Avoidance: by careful planning it is possible to assure that the result will never be larger than can be stored.
# Avoidance: by careful planning it is possible to assure that the result will never be larger than can be stored.
# Handling: If it is anticipated that overflow may occur and when it happens detected and other processing done. Example: it is possible to add two numbers each two bytes wide using just a byte addition in steps: first add the low bytes then add the high bytes, but if it is necessary to carry out of the low bytes this is arithmetic overflow of the byte addition and it necessary to detect and increment the sum of the high bytes. [[Central processing unit|CPUs]] generally have a way of detecting this to support addition of numbers larger than their register size, typically using a status bit.
# Handling: If it is anticipated that overflow may occur and when it happens detected and other processing done. Example: it is possible to add two numbers each two bytes wide using just a byte addition in steps: first add the low bytes then add the high bytes, but if it is necessary to carry out of the low bytes this is arithmetic overflow of the byte addition and it necessary to detect and increment the sum of the high bytes. [[Central processing unit|CPUs]] generally have a way of detecting this to support addition of numbers larger than their register size, typically using a status bit.
# Propagation: if a value is to large to be stored it can be assigned a special value indicating that overflow has occurred and then have all successive operation return this flag value. This is useful so that the problem can be checked for once at the end of a long calculation rather than after each step. This is often supported in Floating Point Hardware called [[FPU]]s.
# Propagation: if a value is too large to be stored it can be assigned a special value indicating that overflow has occurred and then have all successive operation return this flag value. This is useful so that the problem can be checked for once at the end of a long calculation rather than after each step. This is often supported in Floating Point Hardware called [[FPU]]s.
# Ignoring: This usually results in incorrect results and should be avoided.
# Ignoring: This usually results in incorrect results and should be avoided.



Revision as of 18:40, 23 October 2005

The term arithmetic overflow or simply overflow has the following meanings.

  1. In a digital computer, the condition that occurs when a calculation produces a result that is greater than a given register or storage location can store or represent. In other words, exceeding maximum storage space.
  2. In a digital computer, the amount by which a calculated value is greater than that which a given register or storage location can store or represent. Note that the overflow may be placed at another location.

There are several methods of handling overflow:

  1. Avoidance: by careful planning it is possible to assure that the result will never be larger than can be stored.
  2. Handling: If it is anticipated that overflow may occur and when it happens detected and other processing done. Example: it is possible to add two numbers each two bytes wide using just a byte addition in steps: first add the low bytes then add the high bytes, but if it is necessary to carry out of the low bytes this is arithmetic overflow of the byte addition and it necessary to detect and increment the sum of the high bytes. CPUs generally have a way of detecting this to support addition of numbers larger than their register size, typically using a status bit.
  3. Propagation: if a value is too large to be stored it can be assigned a special value indicating that overflow has occurred and then have all successive operation return this flag value. This is useful so that the problem can be checked for once at the end of a long calculation rather than after each step. This is often supported in Floating Point Hardware called FPUs.
  4. Ignoring: This usually results in incorrect results and should be avoided.


It should be noted that division by zero is not a form of arithmetic overflow. Mathematically division by zero is explicitly undefined, it is not that the value is too large but rather that it has no value.

Sources: Federal Standard 1037C and MIL-STD-188 (reference works treating telecommunication)