The termarithmetic underflow (alsofloating-point underflow, or justunderflow) is a condition in acomputer program where the result of a calculation is a number of more precise absolute value than the computer can actually represent inmemory on itscentral processing unit (CPU).
Arithmetic underflow can occur when the true result of afloating-point operation is smaller in magnitude (that is, closer to zero) than the smallest value representable as anormal floating-point number in the targetdatatype.[1] Underflow can in part be regarded as negativeoverflow of theexponent of the floating-point value. For example, if the exponent part can represent values from −128 to 127, then a result with a value less than −128 may cause underflow.
For integers, the term "integer underflow" typically refers to a special kind ofinteger overflow orinteger wraparound condition whereby the result of subtraction would result in a value less than the minimum allowed for a given integer type, i.e. the ideal result was closer to negative infinity than the output type's representable value closest to negative infinity.[2][3][4][5][6]
The interval between −fminN andfminN, wherefminN is the smallest positive normal floating-point value, is called the underflow gap. This is because the size of this interval is many orders of magnitude larger than the distance between adjacent normal floating-point values just outside the gap. For instance, if the floating-point datatype can represent 20 bits, the underflow gap is 221 times larger than the absolute distance between adjacent floating-point values just outside the gap.[7]
In older designs, the underflow gap had just one usable value, zero. When an underflow occurred, the true result was replaced by zero (either directly by the hardware, or by system software handling the primary underflow condition). This replacement is called "flush to zero".
The 1984 edition ofIEEE 754 introducedsubnormal numbers. The subnormal numbers (including zero) fill the underflow gap with values where the absolute distance between adjacent values is the same as for adjacent values just outside the underflow gap. This enables "gradual underflow", where a nearest subnormal value is used, just as a nearest normal value is used when possible. Even when using gradual underflow, the nearest value may be zero.[8]
The absolute distance between adjacent floating-point values just outside the gap is called themachine epsilon, typically characterized by the largest value whose sum with the value 1 will result in the answer with value 1 in that floating-point scheme.[9] This is the maximum value of that satisfies, where is a function which converts the real value into the floating-point representation. While the machine epsilon is not to be confused with the underflow level (assuming subnormal numbers), it is closely related. The machine epsilon is dependent on the number of bits which make up thesignificand, whereas the underflow level depends on the number of digits which make up the exponent field. In most floating-point systems, the underflow level is smaller than the machine epsilon.
The occurrence of an underflow may set a ("sticky") status bit, raise an exception, at the hardware level generate an interrupt, or may cause some combination of these effects.
As specified inIEEE 754, the underflow condition is only signaled if there is also a loss of precision. Typically this is determined as the final result being inexact.However, if the user istrapping on underflow, this may happen regardless of consideration for loss of precision. The default handling in IEEE 754 for underflow (as well as other exceptions) is to record as a floating-point status that underflow has occurred. This is specified for the application-programming level, but often also interpreted as how to handle it at the hardware level.