source: public/doc/gnu-c/Significance-Loss.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 6.5 KB
Line 
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
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing 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<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.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>
60Next: <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> &nbsp; [<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
69means that the number of bits in the significand of the result is
70fewer than the size of the value would permit. If the values being
71subtracted are close enough, but still not equal, a <em>single
72subtraction</em> can wipe out all correct digits, possibly contaminating
73all future computations.
74</p>
75<p>Floating-point calculations can sometimes be carefully designed so
76that significance loss is not possible, such as summing a series where
77all terms have the same sign. For example, the Taylor series
78expansions of the trigonometric and hyperbolic sines have terms of
79identical magnitude, of the general form <code><var>x</var>**(2*<var>n</var> +
801) / (2*<var>n</var> + 1)!</code>. However, those in the trigonometric sine series
81alternate in sign, while those in the hyperbolic sine series are all
82positive. Here is the output of two small programs that sum <var>k</var>
83terms of the series for <code>sin (<var>x</var>)</code>, and compare the computed
84sums with known-to-be-accurate library functions:
85</p>
86<div class="example">
87<pre class="example">x = 10 k = 51
88s (x) = -0.544_021_110_889_270
89sin (x) = -0.544_021_110_889_370
90
91x = 20 k = 81
92s (x) = 0.912_945_250_749_573
93sin (x) = 0.912_945_250_727_628
94
95x = 30 k = 109
96s (x) = -0.987_813_746_058_855
97sin (x) = -0.988_031_624_092_862
98
99x = 40 k = 137
100s (x) = 0.617_400_430_980_474
101sin (x) = 0.745_113_160_479_349
102
103x = 50 k = 159
104s (x) = 57_105.187_673_745_720_532
105sin (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
110x = 10 k = 47
111t (x) = 1.101_323_287_470_340e+04
112sinh (x) = 1.101_323_287_470_339e+04
113
114x = 20 k = 69
115t (x) = 2.425_825_977_048_951e+08
116sinh (x) = 2.425_825_977_048_951e+08
117
118x = 30 k = 87
119t (x) = 5.343_237_290_762_229e+12
120sinh (x) = 5.343_237_290_762_231e+12
121
122x = 40 k = 105
123t (x) = 1.176_926_334_185_100e+17
124sinh (x) = 1.176_926_334_185_100e+17
125
126x = 50 k = 121
127t (x) = 2.592_352_764_293_534e+21
128sinh (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
134high accuracy. By contrast, the series for <code>sin (<var>x</var>)</code>
135suffers increasing significance loss, so that when <var>x</var> = 30 only
136two correct digits remain. Soon after, all digits are wrong, and the
137answers are complete nonsense.
138</p>
139<p>An important skill in numerical programming is to recognize when
140significance loss is likely to contaminate a computation, and revise
141the algorithm to reduce this problem. Sometimes, the only practical
142way to do so is to compute in higher intermediate precision, which is
143why the extended types like <code>long double</code> are important.
144</p>
145
146
147<hr>
148<div class="header">
149<p>
150Next: <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> &nbsp; [<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>
Note: See TracBrowser for help on using the repository browser.