]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/doc/html/math_toolkit/sf_erf/error_function.html
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / doc / html / math_toolkit / sf_erf / error_function.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Error Functions</title>
5 <link rel="stylesheet" href="../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
7 <link rel="home" href="../../index.html" title="Math Toolkit 2.5.1">
8 <link rel="up" href="../sf_erf.html" title="Error Functions">
9 <link rel="prev" href="../sf_erf.html" title="Error Functions">
10 <link rel="next" href="error_inv.html" title="Error Function Inverses">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="../sf_erf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_erf.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="error_inv.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="math_toolkit.sf_erf.error_function"></a><a class="link" href="error_function.html" title="Error Functions">Error Functions</a>
28 </h3></div></div></div>
29 <h5>
30 <a name="math_toolkit.sf_erf.error_function.h0"></a>
31 <span class="phrase"><a name="math_toolkit.sf_erf.error_function.synopsis"></a></span><a class="link" href="error_function.html#math_toolkit.sf_erf.error_function.synopsis">Synopsis</a>
32 </h5>
33 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">erf</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
34 </pre>
35 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
36
37 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
38 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erf</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">);</span>
39
40 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
41 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erf</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
42
43 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
44 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erfc</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">);</span>
45
46 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
47 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erfc</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
48
49 <span class="special">}}</span> <span class="comment">// namespaces</span>
50 </pre>
51 <p>
52 The return type of these functions is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
53 type calculation rules</em></span></a>: the return type is <code class="computeroutput"><span class="keyword">double</span></code> if T is an integer type, and T otherwise.
54 </p>
55 <p>
56 The final <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
57 be used to control the behaviour of the function: how it handles errors,
58 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">policy
59 documentation for more details</a>.
60 </p>
61 <h5>
62 <a name="math_toolkit.sf_erf.error_function.h1"></a>
63 <span class="phrase"><a name="math_toolkit.sf_erf.error_function.description"></a></span><a class="link" href="error_function.html#math_toolkit.sf_erf.error_function.description">Description</a>
64 </h5>
65 <pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
66 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erf</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">);</span>
67
68 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
69 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erf</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
70 </pre>
71 <p>
72 Returns the <a href="http://en.wikipedia.org/wiki/Error_function" target="_top">error
73 function</a> <a href="http://functions.wolfram.com/GammaBetaErf/Erf/" target="_top">erf</a>
74 of z:
75 </p>
76 <p>
77 <span class="inlinemediaobject"><img src="../../../equations/erf1.svg"></span>
78 </p>
79 <p>
80 <span class="inlinemediaobject"><img src="../../../graphs/erf.svg" align="middle"></span>
81 </p>
82 <pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
83 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erfc</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">);</span>
84
85 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
86 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">erfc</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter&#160;15.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
87 </pre>
88 <p>
89 Returns the complement of the <a href="http://functions.wolfram.com/GammaBetaErf/Erfc/" target="_top">error
90 function</a> of z:
91 </p>
92 <p>
93 <span class="inlinemediaobject"><img src="../../../equations/erf2.svg"></span>
94 </p>
95 <p>
96 <span class="inlinemediaobject"><img src="../../../graphs/erfc.svg" align="middle"></span>
97 </p>
98 <h5>
99 <a name="math_toolkit.sf_erf.error_function.h2"></a>
100 <span class="phrase"><a name="math_toolkit.sf_erf.error_function.accuracy"></a></span><a class="link" href="error_function.html#math_toolkit.sf_erf.error_function.accuracy">Accuracy</a>
101 </h5>
102 <p>
103 The following table shows the peak errors (in units of epsilon) found on
104 various platforms with various floating point types, along with comparisons
105 to the <a href="http://www.gnu.org/software/gsl/" target="_top">GSL-1.9</a>, <a href="http://www.gnu.org/software/libc/" target="_top">GNU C Lib</a>, <a href="http://docs.hp.com/en/B9106-90010/index.html" target="_top">HP-UX
106 C Library</a> and <a href="http://www.netlib.org/cephes/" target="_top">Cephes</a>
107 libraries. Unless otherwise specified any floating point type that is narrower
108 than the one shown will have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively
109 zero error</a>.
110 </p>
111 <div class="table">
112 <a name="math_toolkit.sf_erf.error_function.table_erf"></a><p class="title"><b>Table&#160;6.28.&#160;Error rates for erf</b></p>
113 <div class="table-contents"><table class="table" summary="Error rates for erf">
114 <colgroup>
115 <col>
116 <col>
117 <col>
118 <col>
119 <col>
120 </colgroup>
121 <thead><tr>
122 <th>
123 </th>
124 <th>
125 <p>
126 Microsoft Visual C++ version 12.0<br> Win32<br> double
127 </p>
128 </th>
129 <th>
130 <p>
131 GNU C++ version 5.1.0<br> linux<br> long double
132 </p>
133 </th>
134 <th>
135 <p>
136 GNU C++ version 5.1.0<br> linux<br> double
137 </p>
138 </th>
139 <th>
140 <p>
141 Sun compiler version 0x5130<br> Sun Solaris<br> long double
142 </p>
143 </th>
144 </tr></thead>
145 <tbody>
146 <tr>
147 <td>
148 <p>
149 Erf Function: Small Values
150 </p>
151 </td>
152 <td>
153 <p>
154 <span class="blue">Max = 0.996&#949; (Mean = 0.182&#949;)</span><br> <br>
155 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.57&#949; (Mean = 0.317&#949;))
156 </p>
157 </td>
158 <td>
159 <p>
160 <span class="blue">Max = 0.925&#949; (Mean = 0.193&#949;)</span><br> <br>
161 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 0.944&#949; (Mean = 0.191&#949;))<br>
162 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.944&#949; (Mean = 0.191&#949;))
163 </p>
164 </td>
165 <td>
166 <p>
167 <span class="blue">Max = 0.841&#949; (Mean = 0.0687&#949;)</span><br>
168 <br> (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 2.06&#949; (Mean = 0.319&#949;))<br>
169 (<span class="emphasis"><em>Cephes:</em></span> Max = 1.13&#949; (Mean = 0.442&#949;))
170 </p>
171 </td>
172 <td>
173 <p>
174 <span class="blue">Max = 0.925&#949; (Mean = 0.193&#949;)</span><br> <br>
175 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.944&#949; (Mean = 0.194&#949;))
176 </p>
177 </td>
178 </tr>
179 <tr>
180 <td>
181 <p>
182 Erf Function: Medium Values
183 </p>
184 </td>
185 <td>
186 <p>
187 <span class="blue">Max = 1&#949; (Mean = 0.169&#949;)</span><br> <br>
188 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.19&#949; (Mean = 0.244&#949;))
189 </p>
190 </td>
191 <td>
192 <p>
193 <span class="blue">Max = 1.5&#949; (Mean = 0.193&#949;)</span><br> <br>
194 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 0.921&#949; (Mean = 0.0723&#949;))<br>
195 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.921&#949; (Mean = 0.0723&#949;))
196 </p>
197 </td>
198 <td>
199 <p>
200 <span class="blue">Max = 1&#949; (Mean = 0.119&#949;)</span><br> <br>
201 (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 2.31&#949; (Mean = 0.368&#949;))<br>
202 (<span class="emphasis"><em>Cephes:</em></span> Max = 1.34&#949; (Mean = 0.279&#949;))
203 </p>
204 </td>
205 <td>
206 <p>
207 <span class="blue">Max = 1.5&#949; (Mean = 0.202&#949;)</span><br> <br>
208 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.921&#949; (Mean = 0.071&#949;))
209 </p>
210 </td>
211 </tr>
212 <tr>
213 <td>
214 <p>
215 Erf Function: Large Values
216 </p>
217 </td>
218 <td>
219 <p>
220 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>&lt;math.h&gt;:</em></span>
221 Max = 0&#949; (Mean = 0&#949;))
222 </p>
223 </td>
224 <td>
225 <p>
226 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span>
227 Max = 0&#949; (Mean = 0&#949;))<br> (<span class="emphasis"><em>&lt;math.h&gt;:</em></span>
228 Max = 0&#949; (Mean = 0&#949;))
229 </p>
230 </td>
231 <td>
232 <p>
233 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
234 1.16:</em></span> Max = 0&#949; (Mean = 0&#949;))<br> (<span class="emphasis"><em>Cephes:</em></span>
235 Max = 0&#949; (Mean = 0&#949;))
236 </p>
237 </td>
238 <td>
239 <p>
240 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>&lt;math.h&gt;:</em></span>
241 Max = 0&#949; (Mean = 0&#949;))
242 </p>
243 </td>
244 </tr>
245 </tbody>
246 </table></div>
247 </div>
248 <br class="table-break"><div class="table">
249 <a name="math_toolkit.sf_erf.error_function.table_erfc"></a><p class="title"><b>Table&#160;6.29.&#160;Error rates for erfc</b></p>
250 <div class="table-contents"><table class="table" summary="Error rates for erfc">
251 <colgroup>
252 <col>
253 <col>
254 <col>
255 <col>
256 <col>
257 </colgroup>
258 <thead><tr>
259 <th>
260 </th>
261 <th>
262 <p>
263 Microsoft Visual C++ version 12.0<br> Win32<br> double
264 </p>
265 </th>
266 <th>
267 <p>
268 GNU C++ version 5.1.0<br> linux<br> long double
269 </p>
270 </th>
271 <th>
272 <p>
273 GNU C++ version 5.1.0<br> linux<br> double
274 </p>
275 </th>
276 <th>
277 <p>
278 Sun compiler version 0x5130<br> Sun Solaris<br> long double
279 </p>
280 </th>
281 </tr></thead>
282 <tbody>
283 <tr>
284 <td>
285 <p>
286 Erf Function: Small Values
287 </p>
288 </td>
289 <td>
290 <p>
291 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>&lt;math.h&gt;:</em></span>
292 Max = 0&#949; (Mean = 0&#949;))
293 </p>
294 </td>
295 <td>
296 <p>
297 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span>
298 Max = 0&#949; (Mean = 0&#949;))<br> (<span class="emphasis"><em>&lt;math.h&gt;:</em></span>
299 Max = 0&#949; (Mean = 0&#949;))
300 </p>
301 </td>
302 <td>
303 <p>
304 <span class="blue">Max = 0.658&#949; (Mean = 0.0537&#949;)</span><br>
305 <br> (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 1.01&#949; (Mean = 0.485&#949;))<br>
306 (<span class="emphasis"><em>Cephes:</em></span> Max = 0.786&#949; (Mean = 0.0642&#949;))
307 </p>
308 </td>
309 <td>
310 <p>
311 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>&lt;math.h&gt;:</em></span>
312 Max = 0&#949; (Mean = 0&#949;))
313 </p>
314 </td>
315 </tr>
316 <tr>
317 <td>
318 <p>
319 Erf Function: Medium Values
320 </p>
321 </td>
322 <td>
323 <p>
324 <span class="blue">Max = 1.65&#949; (Mean = 0.373&#949;)</span><br> <br>
325 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 2.36&#949; (Mean = 0.539&#949;))
326 </p>
327 </td>
328 <td>
329 <p>
330 <span class="blue">Max = 1.76&#949; (Mean = 0.365&#949;)</span><br> <br>
331 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 1.35&#949; (Mean = 0.307&#949;))<br>
332 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.35&#949; (Mean = 0.307&#949;))
333 </p>
334 </td>
335 <td>
336 <p>
337 <span class="blue">Max = 0.983&#949; (Mean = 0.213&#949;)</span><br> <br>
338 (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 2.64&#949; (Mean = 0.662&#949;))<br>
339 (<span class="emphasis"><em>Cephes:</em></span> Max = 3.59&#949; (Mean = 0.779&#949;))
340 </p>
341 </td>
342 <td>
343 <p>
344 <span class="blue">Max = 1.76&#949; (Mean = 0.383&#949;)</span><br> <br>
345 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 2.81&#949; (Mean = 0.739&#949;))
346 </p>
347 </td>
348 </tr>
349 <tr>
350 <td>
351 <p>
352 Erf Function: Large Values
353 </p>
354 </td>
355 <td>
356 <p>
357 <span class="blue">Max = 1.14&#949; (Mean = 0.248&#949;)</span><br> <br>
358 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.84&#949; (Mean = 0.331&#949;))
359 </p>
360 </td>
361 <td>
362 <p>
363 <span class="blue">Max = 1.57&#949; (Mean = 0.542&#949;)</span><br> <br>
364 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 1.26&#949; (Mean = 0.441&#949;))<br>
365 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.26&#949; (Mean = 0.441&#949;))
366 </p>
367 </td>
368 <td>
369 <p>
370 <span class="blue">Max = 0.868&#949; (Mean = 0.147&#949;)</span><br> <br>
371 (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 3.9&#949; (Mean = 0.472&#949;))<br>
372 (<span class="emphasis"><em>Cephes:</em></span> Max = 2.74&#949; (Mean = 0.413&#949;))
373 </p>
374 </td>
375 <td>
376 <p>
377 <span class="blue">Max = 1.57&#949; (Mean = 0.564&#949;)</span><br> <br>
378 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 4.91&#949; (Mean = 1.54&#949;))
379 </p>
380 </td>
381 </tr>
382 </tbody>
383 </table></div>
384 </div>
385 <br class="table-break"><h5>
386 <a name="math_toolkit.sf_erf.error_function.h3"></a>
387 <span class="phrase"><a name="math_toolkit.sf_erf.error_function.testing"></a></span><a class="link" href="error_function.html#math_toolkit.sf_erf.error_function.testing">Testing</a>
388 </h5>
389 <p>
390 The tests for these functions come in two parts: basic sanity checks use
391 spot values calculated using <a href="http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=Erf" target="_top">Mathworld's
392 online evaluator</a>, while accuracy checks use high-precision test values
393 calculated at 1000-bit precision with <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL::RR</a>
394 and this implementation. Note that the generic and type-specific versions
395 of these functions use differing implementations internally, so this gives
396 us reasonably independent test data. Using our test data to test other "known
397 good" implementations also provides an additional sanity check.
398 </p>
399 <h5>
400 <a name="math_toolkit.sf_erf.error_function.h4"></a>
401 <span class="phrase"><a name="math_toolkit.sf_erf.error_function.implementation"></a></span><a class="link" href="error_function.html#math_toolkit.sf_erf.error_function.implementation">Implementation</a>
402 </h5>
403 <p>
404 All versions of these functions first use the usual reflection formulas to
405 make their arguments positive:
406 </p>
407 <pre class="programlisting"><span class="identifier">erf</span><span class="special">(-</span><span class="identifier">z</span><span class="special">)</span> <span class="special">=</span> <span class="number">1</span> <span class="special">-</span> <span class="identifier">erf</span><span class="special">(</span><span class="identifier">z</span><span class="special">);</span>
408
409 <span class="identifier">erfc</span><span class="special">(-</span><span class="identifier">z</span><span class="special">)</span> <span class="special">=</span> <span class="number">2</span> <span class="special">-</span> <span class="identifier">erfc</span><span class="special">(</span><span class="identifier">z</span><span class="special">);</span> <span class="comment">// preferred when -z &lt; -0.5</span>
410
411 <span class="identifier">erfc</span><span class="special">(-</span><span class="identifier">z</span><span class="special">)</span> <span class="special">=</span> <span class="number">1</span> <span class="special">+</span> <span class="identifier">erf</span><span class="special">(</span><span class="identifier">z</span><span class="special">);</span> <span class="comment">// preferred when -0.5 &lt;= -z &lt; 0</span>
412 </pre>
413 <p>
414 The generic versions of these functions are implemented in terms of the incomplete
415 gamma function.
416 </p>
417 <p>
418 When the significand (mantissa) size is recognised (currently for 53, 64
419 and 113-bit reals, plus single-precision 24-bit handled via promotion to
420 double) then a series of rational approximations <a class="link" href="../sf_implementation.html#math_toolkit.sf_implementation.rational_approximations_used">devised
421 by JM</a> are used.
422 </p>
423 <p>
424 For <code class="computeroutput"><span class="identifier">z</span> <span class="special">&lt;=</span>
425 <span class="number">0.5</span></code> then a rational approximation to
426 erf is used, based on the observation that erf is an odd function and therefore
427 erf is calculated using:
428 </p>
429 <pre class="programlisting"><span class="identifier">erf</span><span class="special">(</span><span class="identifier">z</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">z</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">C</span> <span class="special">+</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">z</span><span class="special">*</span><span class="identifier">z</span><span class="special">));</span>
430 </pre>
431 <p>
432 where the rational approximation R(z*z) is optimised for absolute error:
433 as long as its absolute error is small enough compared to the constant C,
434 then any round-off error incurred during the computation of R(z*z) will effectively
435 disappear from the result. As a result the error for erf and erfc in this
436 region is very low: the last bit is incorrect in only a very small number
437 of cases.
438 </p>
439 <p>
440 For <code class="computeroutput"><span class="identifier">z</span> <span class="special">&gt;</span>
441 <span class="number">0.5</span></code> we observe that over a small interval
442 [a, b) then:
443 </p>
444 <pre class="programlisting"><span class="identifier">erfc</span><span class="special">(</span><span class="identifier">z</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">exp</span><span class="special">(</span><span class="identifier">z</span><span class="special">*</span><span class="identifier">z</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">z</span> <span class="special">~</span> <span class="identifier">c</span>
445 </pre>
446 <p>
447 for some constant c.
448 </p>
449 <p>
450 Therefore for <code class="computeroutput"><span class="identifier">z</span> <span class="special">&gt;</span>
451 <span class="number">0.5</span></code> we calculate erfc using:
452 </p>
453 <pre class="programlisting"><span class="identifier">erfc</span><span class="special">(</span><span class="identifier">z</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">exp</span><span class="special">(-</span><span class="identifier">z</span><span class="special">*</span><span class="identifier">z</span><span class="special">)</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">C</span> <span class="special">+</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">z</span> <span class="special">-</span> <span class="identifier">B</span><span class="special">))</span> <span class="special">/</span> <span class="identifier">z</span><span class="special">;</span>
454 </pre>
455 <p>
456 Again R(z - B) is optimised for absolute error, and the constant <code class="computeroutput"><span class="identifier">C</span></code> is the average of <code class="computeroutput"><span class="identifier">erfc</span><span class="special">(</span><span class="identifier">z</span><span class="special">)</span>
457 <span class="special">*</span> <span class="identifier">exp</span><span class="special">(</span><span class="identifier">z</span><span class="special">*</span><span class="identifier">z</span><span class="special">)</span> <span class="special">*</span>
458 <span class="identifier">z</span></code> taken at the endpoints of the
459 range. Once again, as long as the absolute error in R(z - B) is small compared
460 to <code class="computeroutput"><span class="identifier">c</span></code> then <code class="computeroutput"><span class="identifier">c</span>
461 <span class="special">+</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">z</span> <span class="special">-</span>
462 <span class="identifier">B</span><span class="special">)</span></code>
463 will be correctly rounded, and the error in the result will depend only on
464 the accuracy of the exp function. In practice, in all but a very small number
465 of cases, the error is confined to the last bit of the result. The constant
466 <code class="computeroutput"><span class="identifier">B</span></code> is chosen so that the left
467 hand end of the range of the rational approximation is 0.
468 </p>
469 <p>
470 For large <code class="computeroutput"><span class="identifier">z</span></code> over a range
471 [a, +&#8734;] the above approximation is modified to:
472 </p>
473 <pre class="programlisting"><span class="identifier">erfc</span><span class="special">(</span><span class="identifier">z</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">exp</span><span class="special">(-</span><span class="identifier">z</span><span class="special">*</span><span class="identifier">z</span><span class="special">)</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">C</span> <span class="special">+</span> <span class="identifier">R</span><span class="special">(</span><span class="number">1</span> <span class="special">/</span> <span class="identifier">z</span><span class="special">))</span> <span class="special">/</span> <span class="identifier">z</span><span class="special">;</span>
474 </pre>
475 </div>
476 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
477 <td align="left"></td>
478 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
479 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
480 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;de, Gautam Sewani,
481 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
482 Distributed under the Boost Software License, Version 1.0. (See accompanying
483 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
484 </p>
485 </div></td>
486 </tr></table>
487 <hr>
488 <div class="spirit-nav">
489 <a accesskey="p" href="../sf_erf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_erf.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="error_inv.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
490 </div>
491 </body>
492 </html>