Appendix: Accuracy
of
Numerical Calculations
177
Regarding
the
first misconception, example
1
would
behave
in the
same perverse
way if it
suffered
only
one
rounding error,
the one
that
produces R(x)
—
I
or
0.9999999999,
in
error
by
less
than
one
unit
in its
last
(10th) significant digit.
Regarding
the
second misconception, cancellation
is
what happens
when
two nearly equal numbers are subtracted. For example,
calculating
c(x)
— (1 —
cosx)/x2
in
Radians mode
for
small values
of x is
hazardous because
of
cancellation. Using
x
—
l.2X
10~5
and
rounding results
to 10
digits,
cos
x =
0.9999999999
and
1
-
cos
x =
0.0000000001
with cancellation leaving maybe
one
significant digit
in the
numerator.
Also
x2
=
1.44X10-10.
Then
C(
x) =
0.6944.
This
calculated value
is
wrong because
0
^
c(x)
<
l/i
for all x
¥^
0. To
avoid
numerical cancellation, exploit
the
trigonometric identity
cos
x = 1
—
2
sin2(x/2)
to
cancel
the 1
exactly
and
obtain
a
better
formula
1
/
sin
(x/2)
\
2
\
)
When
this
latter expression
is
evaluated
(in
Radians mode)
at
x
—
1.2 X
10~5,
the
computed result C(x)
—
Q.5
is
correct
to 10
significant
digits.
This
example, while explaining
the
meaning
of
the
word "cancellation," suggests
that
it is
always
a bad
thing.
That
is
another misconception
to be
dispatched later.
For the