Floating Point Arithmetic 1
1.4 Floating Point Arithmetic
1. Determine the value of each of the following expressions using 4-digit rounding
and 4-digit chopping arithmetic. For each quantity, compute the absolute and
the relative error.
(a) π+ecos 22
(b) e/7 + 2 ln π
(c) πln 2 + 10 cos 22
(d) ln 2 10 + tan 22/73
9
(a) To ten digits π+ecos 22= 4.932690627. In chopping arithmetic, we first
calculate
In rounding arithmetic, we calculate
2Section 1.4
(b) To ten digits e/7 + 2 ln π= 2.007218505. In chopping arithmetic, we first
calculate
Finally,
In rounding arithmetic, we calculate
Finally,
Floating Point Arithmetic 3
In rounding arithmetic, we calculate
(d) To ten digits (ln 2 10 + tan 22)/(7 3
9) = 0.1418283677. For the nu-
merator, we first calculate
4Section 1.4
For the denominator,
Finally
Working in rounding arithmetic, we first calculate
Then
Finally
In the following table, δdenotes the absolute error and ǫthe relative error.
2. Identify the potential roundoff error problems in the following algorithm for
calculating the roots of the quadratic equation ax2+bx +c= 0.
GIVEN: real coefficients a,b,c
STEP 1: calculate disc =b24ac
STEP 2: calculate root1 = (b+disc)/(2a)
STEP 3: calculate root2 = c/(a·root1)
OUTPUT: root1 and root2
Note that this algorithm uses the fact that the product of the roots of ax2+
bx +c= 0 is equal to c/a.
3. Identify the potential roundoff error problems in the following algorithm for
calculating the roots of the quadratic equation ax2+bx +c= 0.
GIVEN: real coefficients a,b,c
STEP 1: calculate disc =b24ac
STEP 2: calculate root1 = 2c/(b+disc)
STEP 3: calculate root2 = (b/a)root1
OUTPUT: root1 and root2
Note that this algorithm uses the fact that the sum of the roots of ax2+bx+c= 0
is equal to b/a.
4. Construct an algorithm which computes the roots of the quadratic equation
ax2+bx +c= 0 and which avoids as many roundoff error problems as possible.
Test your algorithm by computing the roots of the quadratic equations 0.2x2
47.91x+ 6 = 0 and 0.025x2+ 7x0.1 = 0. Use 4 decimal digit rounding
arithmetic in your calculations.
6Section 1.4
Both values are correct to the digits shown.
5. Show that the relative error incurred by using x2+x3
6to approximate ex
cos xxis roughly 1024 for |x| ≤ 5×108.
Let f(x) = excos xx. Then, by Taylor’s theorem
6. In the floating point number system F(10,10,98,100), subtract each of the
following pairs of numbers. How many significant decimal digits are lost in
performing the subtraction, and how does this compare with the number of
significant decimal digits to which the numbers agree?
(a) 355/113 and π
(b) 685/252 and e
(c) cos(0.1) and cos(0.11)
(d) 103/280 and 1/e
(a) In F(10,10,98,100),
(b) In F(10,10,98,100),
(c) In F(10,10,98,100),
8Section 1.4
(d) In F(10,10,98,100),
7. (a) To how many significant decimal digits do the numbers 10002 and 10001
agree?
(b) In the floating point number system F(10,10,98,100), subtract 10001
from 10002. How many significant decimal digits are lost in performing
the subtraction?
(c) Explain how you would rearrange your computations to obtain a more
accurate answer.
(a) Because
(b) In F(10,10,98,100),
Floating Point Arithmetic 9
8. (a) For what values of xdoes (1 cos x)/x2= 1/2 to full machine precision.
Consider both IEEE standard single precision and double precision. (Hint:
Use Taylor series.)
(b) Repeat part (a) to determine the values of xfor which ex= 1 to full
machine precision.
(c) Repeat part (a) to determine the positive values of xfor which
ln(1 + x)cos xx=1 to full machine precision.
(a) Using the standard Taylor series expansion for cos x, we find
(b) By Taylor’s theorem,
10 Section 1.4
(c) Using the standard Taylor series expansion for ln(1 + x)and cos x, we find
9. (a) Plot the function f(x) = 1 cos xover the interval 5×108x
5×108. Generate points at 1001 uniformly spaced abscissas and perform
all calculations in IEEE standard double precision.
(b) Reformulate fto avoid cancellation error and then repeat part (a).
10. Repeat Exercise 9 for the function f(x) = tan1xsin x.
(a) Here is a graph of f(x) = tan1xsin xover the interval 5×108x
(b) Expanding both tan1xand sin xin Taylor series, we find
12 Section 1.4
11. Repeat Exercise 9 for the function f(x) = ln(1 + x)cos xx+ 1 over the
interval 5×106x5×106.
(a) Here is a graph of f(x) = ln(1+x)cos xx+1 over the interval 5×106
Floating Point Arithmetic 13
(b) Expanding both ln(1 + x)and cos xin Taylor series, we find
12. Near certain values of xeach of the following functions cannot be accurately
computed using the formula as given due to cancellation error. Identify the
values of xwhich are involved (e.g., near x= 0 or large positive x) and propose
a reformulation of the function (e.g., using Taylor series, rationalization, trig
identities, etc.) to remedy the problem.
(a) f(x) = 1 + cos x(b) f(x) = ex+ sin x1
(c) f(x) = ln xln(1/x)(d) f(x) = x2+ 1 x2+ 4
(e) f(x) = 1 2 sin2x(f) f(x) = ln(x+x2+ 1)
(g) f(x) = xsin x(h) f(x) = ln x1
(a) When x(2n+ 1)π, for any integer n,cos x≈ −1, and there will be
14 Section 1.4
expansions for exand sin xto reformulate the function as
(c) When xis near 1, ln xln(1/x), and there will be cancellation error in the
(d) For large positive and negative x,x2+ 1 x2+ 4, so there will be cancel-
(e) When xis near π
(f) For large negative values of x,x2+ 1 ≈ |x|=x, so there will be cancella-
(g) When xis near 0, xsin x, so there will be cancellation error in the calculation
Floating Point Arithmetic 15
13. (a) Verify that
f(x) = 1 sin xand g(x) = cos2x
1 + sin x
are identical functions.
(b) Which function should be used for computations when xis near π/2? Why?
(c) Which function should be used for computations when xis near 3π/2?
Why?
(a) Note that
14. It was noted that evaluation of the expression
333.5b6+a211a2b2b6121b42+ 5.5b8+a
2b
when a= 77617.0 and b= 33096.0 requires at least 37 decimal digits of precision.
(a) HP workstations have a double precision extended format which corre-
sponds to the floating point number system F(2,113,16381,16384). Does
this system provide enough precision to evaluate the above expression?
(b) What is the smallest value for kfor which the floating point number system
F(2, k, m, M) provides 37 decimal digits of precision?
16 Section 1.4
(a) In the floating point number system F(2,113,16381,16384), machine pre-
cision with rounding is
(b) In order for the floating point number system F(2, k, m, M)to provide at least
15. Consider the following linear system of equations
3.02 1.05 2.53
4.33 0.56 1.78
0.83 0.54 1.47
x1
x2
x3
=
1.61
7.23
3.38
.
(a) Determine the solution of this system using exact arithmetic during Gaus-
sian elimination.
(b) Determine the solution of this system using 3 decimal digit rounding arith-
metic during Gaussian elimination.
(c) Explain the difference between the answers found in part (a) and those
found in part (b).
(a) To carry out the calculations in exact arithmetic, we first convert all coeffi-
cients and right-hand side components to fractions. Gaussian elimination then
produces
Floating Point Arithmetic 17
(b) Starting from the original matrix, the pivot for the first pass of Gaussian elim-
ination is placed in the first row, first column. The multiplier needed to elimi-
The multiplier needed to eliminate the 0.83 entry in the first column of the
Thus, the final reduced matrix is
16. One strategy for alleviating the accumulation of roundoff error during Gaussian
elimination is known as partial pivoting (a more detailed description of this
process will be provided in Chapter 3). The basic idea is as follows. During the
i-th pass of Gaussian elimination, find the row, starting at row iand running
through the last row of the matrix, which has the largest entry in column i.
Interchange this row with the current row iand proceed with the elimination
phase.
18 Section 1.4
(a) Repeat Exercise 15(b) using this partial pivoting strategy. What is the
relative error in each component of the computed solution?
(b) Repeat the “Linear System of Equations” problem considered in the text
using the partial pivoting strategy. What is the relative error in each
component of the computed solution?
(a) For the first pass using partial pivoting on the matrix in Exercise 15, we note
that the largest entry in the first column is in the second row. We therefore
The multiplier needed to eliminate the 3.02 entry in the first column of the
The matrix for the next pass of Gaussian elimination is then
Thus, the final reduced matrix is
Floating Point Arithmetic 19
(b) For the system of equations in Example 1.11, the largest element in the first
column is originally in the first row. Thus, there is no need to interchange
We now observe that the largest element in the bottom two rows of the second
column is in the third row. We therefore interchange the second and third rows
The multiplier needed to eliminate the 0.0001 entry in the second column of