1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Significance Loss (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Significance Loss (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Significance Loss (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="Floating-Point-in-Depth.html" rel="up" title="Floating Point in Depth">
|
---|
33 | <link href="Fused-Multiply_002dAdd.html" rel="next" title="Fused Multiply-Add">
|
---|
34 | <link href="Rounding-Issues.html" rel="prev" title="Rounding Issues">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Significance-Loss"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Fused-Multiply_002dAdd.html" accesskey="n" rel="next">Fused Multiply-Add</a>, Previous: <a href="Rounding-Issues.html" accesskey="p" rel="prev">Rounding Issues</a>, Up: <a href="Floating-Point-in-Depth.html" accesskey="u" rel="up">Floating Point in Depth</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Significance-Loss-1"></span><h3 class="section">28.9 Significance Loss</h3>
|
---|
64 | <span id="index-significance-loss-_0028floating-point_0029"></span>
|
---|
65 | <span id="index-floating_002dpoint-significance-loss"></span>
|
---|
66 |
|
---|
67 | <p>A much more serious source of error in floating-point computation is
|
---|
68 | <em>significance loss</em> from subtraction of nearly equal values. This
|
---|
69 | means that the number of bits in the significand of the result is
|
---|
70 | fewer than the size of the value would permit. If the values being
|
---|
71 | subtracted are close enough, but still not equal, a <em>single
|
---|
72 | subtraction</em> can wipe out all correct digits, possibly contaminating
|
---|
73 | all future computations.
|
---|
74 | </p>
|
---|
75 | <p>Floating-point calculations can sometimes be carefully designed so
|
---|
76 | that significance loss is not possible, such as summing a series where
|
---|
77 | all terms have the same sign. For example, the Taylor series
|
---|
78 | expansions of the trigonometric and hyperbolic sines have terms of
|
---|
79 | identical magnitude, of the general form <code><var>x</var>**(2*<var>n</var> +
|
---|
80 | 1) / (2*<var>n</var> + 1)!</code>. However, those in the trigonometric sine series
|
---|
81 | alternate in sign, while those in the hyperbolic sine series are all
|
---|
82 | positive. Here is the output of two small programs that sum <var>k</var>
|
---|
83 | terms of the series for <code>sin (<var>x</var>)</code>, and compare the computed
|
---|
84 | sums with known-to-be-accurate library functions:
|
---|
85 | </p>
|
---|
86 | <div class="example">
|
---|
87 | <pre class="example">x = 10 k = 51
|
---|
88 | s (x) = -0.544_021_110_889_270
|
---|
89 | sin (x) = -0.544_021_110_889_370
|
---|
90 |
|
---|
91 | x = 20 k = 81
|
---|
92 | s (x) = 0.912_945_250_749_573
|
---|
93 | sin (x) = 0.912_945_250_727_628
|
---|
94 |
|
---|
95 | x = 30 k = 109
|
---|
96 | s (x) = -0.987_813_746_058_855
|
---|
97 | sin (x) = -0.988_031_624_092_862
|
---|
98 |
|
---|
99 | x = 40 k = 137
|
---|
100 | s (x) = 0.617_400_430_980_474
|
---|
101 | sin (x) = 0.745_113_160_479_349
|
---|
102 |
|
---|
103 | x = 50 k = 159
|
---|
104 | s (x) = 57_105.187_673_745_720_532
|
---|
105 | sin (x) = -0.262_374_853_703_929
|
---|
106 |
|
---|
107 | // sinh(x) series summation with positive signs
|
---|
108 | // with k terms needed to converge to machine precision
|
---|
109 |
|
---|
110 | x = 10 k = 47
|
---|
111 | t (x) = 1.101_323_287_470_340e+04
|
---|
112 | sinh (x) = 1.101_323_287_470_339e+04
|
---|
113 |
|
---|
114 | x = 20 k = 69
|
---|
115 | t (x) = 2.425_825_977_048_951e+08
|
---|
116 | sinh (x) = 2.425_825_977_048_951e+08
|
---|
117 |
|
---|
118 | x = 30 k = 87
|
---|
119 | t (x) = 5.343_237_290_762_229e+12
|
---|
120 | sinh (x) = 5.343_237_290_762_231e+12
|
---|
121 |
|
---|
122 | x = 40 k = 105
|
---|
123 | t (x) = 1.176_926_334_185_100e+17
|
---|
124 | sinh (x) = 1.176_926_334_185_100e+17
|
---|
125 |
|
---|
126 | x = 50 k = 121
|
---|
127 | t (x) = 2.592_352_764_293_534e+21
|
---|
128 | sinh (x) = 2.592_352_764_293_536e+21
|
---|
129 | </pre></div>
|
---|
130 |
|
---|
131 | <p>We have added underscores to the numbers to enhance readability.
|
---|
132 | </p>
|
---|
133 | <p>The <code>sinh (<var>x</var>)</code> series with positive terms can be summed to
|
---|
134 | high accuracy. By contrast, the series for <code>sin (<var>x</var>)</code>
|
---|
135 | suffers increasing significance loss, so that when <var>x</var> = 30 only
|
---|
136 | two correct digits remain. Soon after, all digits are wrong, and the
|
---|
137 | answers are complete nonsense.
|
---|
138 | </p>
|
---|
139 | <p>An important skill in numerical programming is to recognize when
|
---|
140 | significance loss is likely to contaminate a computation, and revise
|
---|
141 | the algorithm to reduce this problem. Sometimes, the only practical
|
---|
142 | way to do so is to compute in higher intermediate precision, which is
|
---|
143 | why the extended types like <code>long double</code> are important.
|
---|
144 | </p>
|
---|
145 |
|
---|
146 |
|
---|
147 | <hr>
|
---|
148 | <div class="header">
|
---|
149 | <p>
|
---|
150 | Next: <a href="Fused-Multiply_002dAdd.html" accesskey="n" rel="next">Fused Multiply-Add</a>, Previous: <a href="Rounding-Issues.html" accesskey="p" rel="prev">Rounding Issues</a>, Up: <a href="Floating-Point-in-Depth.html" accesskey="u" rel="up">Floating Point in Depth</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
151 | </div>
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 | </body>
|
---|
156 | </html>
|
---|