TAOCP 4.2.1 Exercise 8
Let the floating decimal numbers have $p=8$ digits in the fraction, and let normalized numbers satisfy $\frac1{10}\le |f|<1,$ unless the number is zero.
Section 4.2.1: Single-Precision Calculations
Exercise 8. [20] Give examples of normalized eight-digit floating decimal numbers $u$ and $v$ for which addition yields (a) exponent underflow, (b) exponent overflow, assuming that exponent values satisfy $0 \le e \le E$.
Verified: no
Solve time: 1m39s
Solution
Let the floating decimal numbers have $p=8$ digits in the fraction, and let normalized numbers satisfy
$\frac1{10}\le |f|<1,$
unless the number is zero. Exponents are restricted to
$0\le e\le E.$
By Algorithm A, addition first forms the exact sum and then invokes Algorithm N. Exponent underflow occurs in step N6 when normalization requires $e<0$. Exponent overflow occurs in step N6 when normalization requires $e>E$.
(a) Example yielding exponent underflow
Take
v=(0,;-0.99999999\times10^{-1}).$$ Both numbers are normalized eight-digit floating decimal numbers, since their fractions have eight digits and leading digit nonzero. Their sum is $$u+v =0.10000000\times10^{0} -0.099999999\times10^{0} =0.000000001\times10^{0}.
The raw result therefore has
$e=0,\qquad f=0.000000001.$
To normalize, Algorithm N repeatedly executes step N3. The fraction must be shifted left eight places:
$$= 0.10000000\times10^{-8}.$$
Hence the normalized result requires exponent
$e=-8.$
Since $-8<0$, step N6 detects exponent underflow.
Thus
u=(0,0.10000000),\quad v=(0,-0.099999999) }
give exponent underflow.
(b) Example yielding exponent overflow
Take
$$ v=(E,;0.99999999). $$
Both numbers are normalized.
Since the exponents are equal, Algorithm A adds the fractions:
$$ =1.99999998. $$
This exceeds $1$, so step N4 scales right once:
$$= 0.199999998\times10^{E+1}.$$
The normalized result therefore requires exponent
$e=E+1.$
Since $E+1>E$, step N6 detects exponent overflow.
Thus
u=(E,0.99999999),\quad v=(E,0.99999999) }
give exponent overflow. ∎