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">
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>
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>
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>
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>
33 <pre class=
"programlisting"><span class=
"preprocessor">#include
</span> <span class=
"special"><</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">></span>
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>
37 <span class=
"keyword">template
</span> <span class=
"special"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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>
40 <span class=
"keyword">template
</span> <span class=
"special"><</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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">></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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">&);
</span>
43 <span class=
"keyword">template
</span> <span class=
"special"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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>
46 <span class=
"keyword">template
</span> <span class=
"special"><</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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">></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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">&);
</span>
49 <span class=
"special">}}
</span> <span class=
"comment">// namespaces
</span>
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.
56 The final
<a class=
"link" href=
"../../policy.html" title=
"Chapter 15. 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 15. Policies: Controlling Precision, Error Handling etc">policy
59 documentation for more details
</a>.
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>
65 <pre class=
"programlisting"><span class=
"keyword">template
</span> <span class=
"special"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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>
68 <span class=
"keyword">template
</span> <span class=
"special"><</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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">></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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">&);
</span>
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>
77 <span class=
"inlinemediaobject"><img src=
"../../../equations/erf1.svg"></span>
80 <span class=
"inlinemediaobject"><img src=
"../../../graphs/erf.svg" align=
"middle"></span>
82 <pre class=
"programlisting"><span class=
"keyword">template
</span> <span class=
"special"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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>
85 <span class=
"keyword">template
</span> <span class=
"special"><</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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">></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 15. Policies: Controlling Precision, Error Handling etc">Policy
</a><span class=
"special">&);
</span>
89 Returns the complement of the
<a href=
"http://functions.wolfram.com/GammaBetaErf/Erfc/" target=
"_top">error
93 <span class=
"inlinemediaobject"><img src=
"../../../equations/erf2.svg"></span>
96 <span class=
"inlinemediaobject"><img src=
"../../../graphs/erfc.svg" align=
"middle"></span>
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>
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
112 <a name=
"math_toolkit.sf_erf.error_function.table_erf"></a><p class=
"title"><b>Table
 6.28.
 Error rates for erf
</b></p>
113 <div class=
"table-contents"><table class=
"table" summary=
"Error rates for erf">
126 Microsoft Visual C++ version
12.0<br> Win32
<br> double
131 GNU C++ version
5.1.0<br> linux
<br> long double
136 GNU C++ version
5.1.0<br> linux
<br> double
141 Sun compiler version
0x5130<br> Sun Solaris
<br> long double
149 Erf Function: Small Values
154 <span class=
"blue">Max =
0.996ε (Mean =
0.182ε)
</span><br> <br>
155 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
1.57ε (Mean =
0.317ε))
160 <span class=
"blue">Max =
0.925ε (Mean =
0.193ε)
</span><br> <br>
161 (
<span class=
"emphasis"><em><tr1/cmath
>:
</em></span> Max =
0.944ε (Mean =
0.191ε))
<br>
162 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
0.944ε (Mean =
0.191ε))
167 <span class=
"blue">Max =
0.841ε (Mean =
0.0687ε)
</span><br>
168 <br> (
<span class=
"emphasis"><em>GSL
1.16:
</em></span> Max =
2.06ε (Mean =
0.319ε))
<br>
169 (
<span class=
"emphasis"><em>Cephes:
</em></span> Max =
1.13ε (Mean =
0.442ε))
174 <span class=
"blue">Max =
0.925ε (Mean =
0.193ε)
</span><br> <br>
175 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
0.944ε (Mean =
0.194ε))
182 Erf Function: Medium Values
187 <span class=
"blue">Max =
1ε (Mean =
0.169ε)
</span><br> <br>
188 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
1.19ε (Mean =
0.244ε))
193 <span class=
"blue">Max =
1.5ε (Mean =
0.193ε)
</span><br> <br>
194 (
<span class=
"emphasis"><em><tr1/cmath
>:
</em></span> Max =
0.921ε (Mean =
0.0723ε))
<br>
195 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
0.921ε (Mean =
0.0723ε))
200 <span class=
"blue">Max =
1ε (Mean =
0.119ε)
</span><br> <br>
201 (
<span class=
"emphasis"><em>GSL
1.16:
</em></span> Max =
2.31ε (Mean =
0.368ε))
<br>
202 (
<span class=
"emphasis"><em>Cephes:
</em></span> Max =
1.34ε (Mean =
0.279ε))
207 <span class=
"blue">Max =
1.5ε (Mean =
0.202ε)
</span><br> <br>
208 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
0.921ε (Mean =
0.071ε))
215 Erf Function: Large Values
220 <span class=
"blue">Max =
0ε (Mean =
0ε)
</span><br> <br> (
<span class=
"emphasis"><em><math.h
>:
</em></span>
221 Max =
0ε (Mean =
0ε))
226 <span class=
"blue">Max =
0ε (Mean =
0ε)
</span><br> <br> (
<span class=
"emphasis"><em><tr1/cmath
>:
</em></span>
227 Max =
0ε (Mean =
0ε))
<br> (
<span class=
"emphasis"><em><math.h
>:
</em></span>
228 Max =
0ε (Mean =
0ε))
233 <span class=
"blue">Max =
0ε (Mean =
0ε)
</span><br> <br> (
<span class=
"emphasis"><em>GSL
234 1.16:
</em></span> Max =
0ε (Mean =
0ε))
<br> (
<span class=
"emphasis"><em>Cephes:
</em></span>
235 Max =
0ε (Mean =
0ε))
240 <span class=
"blue">Max =
0ε (Mean =
0ε)
</span><br> <br> (
<span class=
"emphasis"><em><math.h
>:
</em></span>
241 Max =
0ε (Mean =
0ε))
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
 6.29.
 Error rates for erfc
</b></p>
250 <div class=
"table-contents"><table class=
"table" summary=
"Error rates for erfc">
263 Microsoft Visual C++ version
12.0<br> Win32
<br> double
268 GNU C++ version
5.1.0<br> linux
<br> long double
273 GNU C++ version
5.1.0<br> linux
<br> double
278 Sun compiler version
0x5130<br> Sun Solaris
<br> long double
286 Erf Function: Small Values
291 <span class=
"blue">Max =
0ε (Mean =
0ε)
</span><br> <br> (
<span class=
"emphasis"><em><math.h
>:
</em></span>
292 Max =
0ε (Mean =
0ε))
297 <span class=
"blue">Max =
0ε (Mean =
0ε)
</span><br> <br> (
<span class=
"emphasis"><em><tr1/cmath
>:
</em></span>
298 Max =
0ε (Mean =
0ε))
<br> (
<span class=
"emphasis"><em><math.h
>:
</em></span>
299 Max =
0ε (Mean =
0ε))
304 <span class=
"blue">Max =
0.658ε (Mean =
0.0537ε)
</span><br>
305 <br> (
<span class=
"emphasis"><em>GSL
1.16:
</em></span> Max =
1.01ε (Mean =
0.485ε))
<br>
306 (
<span class=
"emphasis"><em>Cephes:
</em></span> Max =
0.786ε (Mean =
0.0642ε))
311 <span class=
"blue">Max =
0ε (Mean =
0ε)
</span><br> <br> (
<span class=
"emphasis"><em><math.h
>:
</em></span>
312 Max =
0ε (Mean =
0ε))
319 Erf Function: Medium Values
324 <span class=
"blue">Max =
1.65ε (Mean =
0.373ε)
</span><br> <br>
325 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
2.36ε (Mean =
0.539ε))
330 <span class=
"blue">Max =
1.76ε (Mean =
0.365ε)
</span><br> <br>
331 (
<span class=
"emphasis"><em><tr1/cmath
>:
</em></span> Max =
1.35ε (Mean =
0.307ε))
<br>
332 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
1.35ε (Mean =
0.307ε))
337 <span class=
"blue">Max =
0.983ε (Mean =
0.213ε)
</span><br> <br>
338 (
<span class=
"emphasis"><em>GSL
1.16:
</em></span> Max =
2.64ε (Mean =
0.662ε))
<br>
339 (
<span class=
"emphasis"><em>Cephes:
</em></span> Max =
3.59ε (Mean =
0.779ε))
344 <span class=
"blue">Max =
1.76ε (Mean =
0.383ε)
</span><br> <br>
345 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
2.81ε (Mean =
0.739ε))
352 Erf Function: Large Values
357 <span class=
"blue">Max =
1.14ε (Mean =
0.248ε)
</span><br> <br>
358 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
1.84ε (Mean =
0.331ε))
363 <span class=
"blue">Max =
1.57ε (Mean =
0.542ε)
</span><br> <br>
364 (
<span class=
"emphasis"><em><tr1/cmath
>:
</em></span> Max =
1.26ε (Mean =
0.441ε))
<br>
365 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
1.26ε (Mean =
0.441ε))
370 <span class=
"blue">Max =
0.868ε (Mean =
0.147ε)
</span><br> <br>
371 (
<span class=
"emphasis"><em>GSL
1.16:
</em></span> Max =
3.9ε (Mean =
0.472ε))
<br>
372 (
<span class=
"emphasis"><em>Cephes:
</em></span> Max =
2.74ε (Mean =
0.413ε))
377 <span class=
"blue">Max =
1.57ε (Mean =
0.564ε)
</span><br> <br>
378 (
<span class=
"emphasis"><em><math.h
>:
</em></span> Max =
4.91ε (Mean =
1.54ε))
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>
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.
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>
404 All versions of these functions first use the usual reflection formulas to
405 make their arguments positive:
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>
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
< -
0.5</span>
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 <= -z
< 0</span>
414 The generic versions of these functions are implemented in terms of the incomplete
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
424 For
<code class=
"computeroutput"><span class=
"identifier">z
</span> <span class=
"special"><=
</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:
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>
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
440 For
<code class=
"computeroutput"><span class=
"identifier">z
</span> <span class=
"special">></span>
441 <span class=
"number">0.5</span></code> we observe that over a small interval
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>
450 Therefore for
<code class=
"computeroutput"><span class=
"identifier">z
</span> <span class=
"special">></span>
451 <span class=
"number">0.5</span></code> we calculate erfc using:
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>
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.
470 For large
<code class=
"computeroutput"><span class=
"identifier">z
</span></code> over a range
471 [a, +
∞] the above approximation is modified to:
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>
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
© 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
å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>)
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>