Underflow, overflow, approximation & rounding error
What is underflow and what is overflow?
In computer science, real numbers are represented in normalized floating-point representation. a floating-point representation consists of 2 parts: the mantissa and the exponent. Each part uses a particular number of bits. Due to the limitation of bits numbers, a fixed-number-of-bits representation has a range of numbers that can be represented. If a real number is too small, beyond the lower boundary of the range, it cannot be represented. This is underflow. If a real number is too large, beyond the upper boundary of the range, it cannot be represented either. This is overflow.
Why may a floating-point representation be an approximation?
Due to the limit of numbers of bits, a floating-point representation has a certain number of bits. some real numbers cannot be represented in binary form as exactly as in math. For example, -42.5, in binary form, it is
mantissa -> 10101011, 8 bits
exponent -> 0110, 4 bits
this form represents the value -42.5 exactly as in math.
but if 6 bits are used for mantissa, the last 2 bits 11 would be lost and it would be:
mantissa -> 101010, 6 bits
exponent -> 0110, 4 bits
but the new form represents the value -44, NOT -42.5. This happens because the limit of bits used to store the mantissa and exponent.
Another example is number 0.4. The ideal binary form is
0 0110 0110 0110 0110 0110 …
In a real computer system, we have to decide how many numbers of bits should be used to represent a number. We cannot use infinite number of bits for 0.4. The ideal binary form has to be truncated. This generates approximation too.
What is rounding error?
Rounding error/round-off error is the difference between the result produced by a given algorithm using exact arithmetic and the result produced by a finite-precision and rounded arithmetic.
Due to the fact that binary representation of a real number might be an approximation, computer algorithms might produce rounding errors.
Accuracy and Range
The number of bits used to represent a real number in floating-point representation affects the accuracy and range of numbers. The more bits for mantissa, the more accurate the number can be; the more bits for exponent, the wider range of numbers can be represented.