TAOCP 4.2.1 Exercise 4

We apply Algorithm A with base $b=10$ and precision $p=8$.

Section 4.2.1: Single-Precision Calculations

Exercise 4. ▶ [16] Assume that $b = 10$, $p = 8$. What result does Algorithm A give for $(50, +.89765432) \oplus (49, +.33333333)$? For $(53, -.99987654) \oplus (54, +1.0000000)$? For $(45, -.50000001) \oplus (54, +1.0000000)$?

Verified: yes
Solve time: 4m30s


Solution

We apply Algorithm A with base $b=10$ and precision $p=8$. After the fractions are aligned and added, Algorithm N is used to normalize and round the result to eight digits.

(a) $(50,+.89765432)\oplus(49,+.33333333)$

The exponents differ by $1$, so the second fraction is shifted right one decimal place:

$$ .33333333 \mapsto .033333333. $$

Thus

$$ f_w=.89765432+.033333333=.930987653, \qquad e_w=50. $$

Since

$$ \frac1{10}\le .930987653<1, $$

the result is already normalized.

Rounding to $p=8$ digits, we inspect the ninth digit:

$$ .930987653. $$

The ninth digit is $3$, so no increment occurs:

$$ .930987653 \longrightarrow .93098765. $$

Hence

$$ \boxed{(50,+.89765432)\oplus(49,+.33333333) =(50,+.93098765).} $$

(b) $(53,-.99987654)\oplus(54,+1.0000000)$

The larger exponent is $54$, so we align the second operand to that exponent. The fraction with exponent $53$ is shifted right one decimal place:

$$ -.99987654 \mapsto -.099987654. $$

Now add:

$$ f_w=.100000000-.099987654=.000012346, \qquad e_w=54. $$

The fraction is not normalized, since

$$ .000012346<\frac1{10}. $$

Algorithm N multiplies the fraction by $10$ and decreases the exponent by $1$ until normalization is achieved:

$$ (54,.000012346) \to (53,.00012346) \to (52,.0012346) \to (51,.012346) \to (50,.12346). $$

Now

$$ \frac1{10}\le .12346<1, $$

so the number is normalized.

Writing the fraction with eight digits,

$$ .12346=.12346000, $$

and no rounding change is required.

Therefore

$$ \boxed{(53,-.99987654)\oplus(54,+1.0000000) =(50,+.12346000).} $$

(c) $(45,-.50000001)\oplus(54,+1.0000000)$

The exponent difference is

$$ 54-45=9. $$

Since

$$ 9<p+2=10, $$

Algorithm A does not discard the smaller operand.

Shift the fraction with exponent $45$ right by $9$ decimal places:

$$ -.50000001 \mapsto -.00000000050000001. $$

Using exponent $54$, the other fraction is

$$ +.10000000000000000. $$

Hence

$$ f_w = .10000000000000000 - .00000000050000001 = .09999999949999999, \qquad e_w=54. $$

Since

$$ .09999999949999999<\frac1{10}, $$

the result is not normalized. One normalization step gives

$$ e=53, \qquad f=.9999999949999999. $$

Now

$$ \frac1{10}\le .9999999949999999<1, $$

so the number is normalized.

To round to eight digits, inspect the ninth digit:

$$ .9999999949999999. $$

The first eight digits are $99999999$, and the ninth digit is $4$. Therefore no increment occurs, yielding

$$ .99999999. $$

Thus

$$ \boxed{(45,-.50000001)\oplus(54,+1.0000000) =(53,+.99999999).} $$

Therefore the three results are

$$ \boxed{(50,+.93098765)}, \qquad \boxed{(50,+.12346000)}, \qquad \boxed{(53,+.99999999)}. $$