What Is an Arithmetic Overflow?

Arithmetic overflow means that the result of an arithmetic operation performed by a computer is beyond the range that the machine can represent. Overflow is divided into overflow and underflow. In fixed-point and floating-point computers, the concepts of overflow and underflow are not exactly the same. In fixed-point computers, the range of numbers that exceed the number from the positive direction is called overflow; the range of numbers that exceed the number from the negative direction is called underflow. In floating-point computers, the range of representation of floating-point numbers is mainly determined by the order code. Regardless of whether the sign of the number is positive or negative, if the order code exceeds the range of the order code from the positive direction, it is called overflow; if the order code exceeds the range of the order code from the negative direction, or the mantissa is "0", Collectively called underflow. Generally speaking, the computer automatically treats the floating-point number underflow as "0" and does not output an error message. For the overflow generated, the computer generates an "overflow interrupt" and outputs an overflow error message, or even stops. Operation of the program [1] .

Arithmetic overflow or overflow for short refers to: the overflow condition that occurs in the computer field is that when a single numerical calculation is run, the result of the calculation is very large, which is greater than the register or memory. Ability to store or represent limitations. In the computer field, when running multiple or cumulative numerical calculations, when the total value generated by the calculation is very large, it is greater than the ability to be stored or represented by a register or memory. Note that the overflow may be replaced at another address.
Arithmetic underflow is also called floating-point underflow, which means that the result of computer floating-point calculation is less than the minimum number that can be represented. Arithmetic underflow occurs when the calculation result is close to zero, making the size of the calculation result smaller than the smallest number that a floating point number can represent. Arithmetic underflow can also be considered as the overflow of a floating-point number index when it is negative. For example, floating-point exponents range from -128 to 127, and a floating-point number with an absolute value less than 2127 will cause underflow (assuming a -128 order code is used to represent negative infinity). The interval between fminN and fminN is called the underflow gap, where fminN is the smallest positive number that can be represented by the general floating-point format.
In the early design, the numbers between the underflow intervals were regarded as zero. Therefore, if an arithmetic underflow occurs, the result will be changed to zero, which may be processed by hardware or system software. This processing method is called Flush to zero.
The 1984 version of IEEE 754 introduced subnormal numbers. Subnormal numbers and zeros can fill the underflow gap. Assuming that the floating-point exponent ranges from -128 to 127, the smallest representable normal number is 2 ^ 127, and the subnormal number is a number like 0.9 ^ 127, 0.8 ^ 127, etc. The result will be converted during calculation Is the closest subnormal number, so it can be asymptotically underflow, but the closest subnormal number may still be zero.
When an arithmetic underflow occurs, a status bit may be set, an exception may occur, an interrupt may be generated, or a combination of these.
There are several ways to control overflow:
  1. Design: Select the correct data type. Pay particular attention to the data length and signed / unsigned data symbols.
  2. Avoidance: Pay attention to the operation of the instruction and check the value of the calculation in advance, it may ensure that the calculated result does not exceed the limit of the data stored in the memory.
  3. Control: When it is detected, and it is detected when other processes are completed, then the overflow can be expected. For example, two numbers with two large bits are used for addition calculation. This situation is most likely to occur. The steps are as follows: first add the low bit and then the high bit. Overflow, then it is necessary to do detection and increase the sum of high bits. Generally, the CPU supports the method of detecting that the value addition is larger than the register size. Basically, this method uses the status bit method.
  4. Value-added: If the stored value is too large, it will be allocated to other specific values, then overflow will occur, and then the continuous operation will occur when the flag value is returned. The most useful way to check this problem is to do a one-time check at the end of the overall calculation, instead of checking every running step. This method is most commonly used to call floating-point arithmetic in floating-point hardware.
  5. Ignore: This is the most common practice, but it will lead to incorrect results and reduce the security of the program.
Most computers can distinguish between these two overflow conditions. When the result of addition or subtraction is rounded, you must consider that when the value and result of the operation are both of the unsigned numbers type, the result of the operation is not suitable for this numeric type. Therefore, it is useful to check the carry flag after running addition or subtraction of unsigned values (positive numbers). "Overflow" is prone to occur when the result of the operation is an unsigned value. You can predict such situations from the signed operation value (for example: the addition of two positive integers results in a negative number). Therefore, it is very useful to check the overflow flag after running the addition or subtraction of 2's complement (in other words, taking into account the number value).
Definition A and B are binary numbers of length n bits
The following is vertical (the first line is rounded):
among them
Yes
Carry
1. The input number is an unsigned integer. We can determine whether it overflows by observing C.
a) C = 1
i) If it is an addition operation, the result is incorrect and the result overflows
ii) If it is a subtraction operation, the result is correct, and the result does not overflow
b) C = 0
i) If it is an addition operation, the result is correct, and the result does not overflow
ii) If it is a subtraction operation, the result is incorrect and the result does not overflow. In this case, the result is negative. However, in the unsigned integer world, negative numbers do not exist, and we recognize that such operations are illegal. Of course, if the answer is considered to be in the form of a signed integer complement, the result is correct.
2. The input number is a signed integer. We can determine if it overflows by observing V
a) V = 1, the result is incorrect, the result overflows
b) V = 0, the result is correct, the result does not overflow

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?