1
COMPUTER SCIENCE 349A
Handout Number 4
SUBTRACTIVE CANCELLATION
(pages 68-72 of the 5
th
edition; pages 73-76 of
the 6
th
edition)
Subtractive cancellation refers to the loss of significant digits during a floating-
point computation due to the subtraction of nearly equal floating-point numbers.
Note that if
x
ˆ
is an approximation to
0
>
x
and
y
ˆ is an approximation to
0
>
y
,
and if for example
x
ˆ
agrees with
x
to 8 significant digits and
y
ˆ agrees with
y
to 8
significant digits, then
≈
×
y
x
ˆ
ˆ
y
x
×
y
x
y
x
/
ˆ
/
ˆ
≈
y
x
y
x
+
≈
+
ˆ
ˆ
and these values will agree to about 8 significant digits.
However, this may not be true
for subtraction: it is possible that none of the significant digits in
y
x
ˆ
ˆ
−
and
y
x
−
agree.
The following examples illustrate subtractive cancellation, and show how it can
be avoided in each of these cases.
Example 1.
The evaluation of
(
)
x
x
f
−
+
1
2
l
will be inaccurate if
x
is large and positive.
For example, using
10
=
b
,
4
=
k
, idealized
rounding
floating-point arithmetic and
x
= 65.43, we obtain the following (where
(
)
z
f
l
is computed using idealized floating-point arithmetic; that is, the exact value of
z
is
rounded to 4 significant digits).
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
1
2
2
2
4
2
10
1000
.
0
or
01
.
0
43
.
65
44
.
65
1
44
.
65
43699
.
65
4282
1
4282
1
4281
1
10
4281
.
0
or
4281
0849
.
4281
−
×
=
−
=
−
+
=
=
=
+
=
+
=
+
×
=
=
l
l
L
l
l
l
l
l
l
l
f
x
x
f
f
f
x
f
f
x
f
f
x
f
However, the true (exact) value of
x
x
−
+
1
2
is
L
0076413
.
0
.
The relative error in
(
)
x
x
f
−
+
1
2
l
is about 0.31 or 31%.
To avoid the subtractive cancellation above and to obtain an accurate floating-
point result, note that

This ** preview** has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*