]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/doc/html/math_toolkit/sf_gamma/tgamma.html
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / doc / html / math_toolkit / sf_gamma / tgamma.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Gamma</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_gamma.html" title="Gamma Functions">
9 <link rel="prev" href="../sf_gamma.html" title="Gamma Functions">
10 <link rel="next" href="lgamma.html" title="Log Gamma">
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_gamma.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_gamma.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="lgamma.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_gamma.tgamma"></a><a class="link" href="tgamma.html" title="Gamma">Gamma</a>
28 </h3></div></div></div>
29 <h5>
30 <a name="math_toolkit.sf_gamma.tgamma.h0"></a>
31 <span class="phrase"><a name="math_toolkit.sf_gamma.tgamma.synopsis"></a></span><a class="link" href="tgamma.html#math_toolkit.sf_gamma.tgamma.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">gamma</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">tgamma</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">tgamma</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">tgamma1pm1</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">dz</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">tgamma1pm1</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">dz</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 <h5>
52 <a name="math_toolkit.sf_gamma.tgamma.h1"></a>
53 <span class="phrase"><a name="math_toolkit.sf_gamma.tgamma.description"></a></span><a class="link" href="tgamma.html#math_toolkit.sf_gamma.tgamma.description">Description</a>
54 </h5>
55 <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>
56 <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">tgamma</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">);</span>
57
58 <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>
59 <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">tgamma</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>
60 </pre>
61 <p>
62 Returns the "true gamma" (hence name tgamma) of value z:
63 </p>
64 <p>
65 <span class="inlinemediaobject"><img src="../../../equations/gamm1.svg"></span>
66 </p>
67 <p>
68 <span class="inlinemediaobject"><img src="../../../graphs/tgamma.svg" align="middle"></span>
69 </p>
70 <p>
71 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
72 be used to control the behaviour of the function: how it handles errors,
73 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
74 documentation for more details</a>.
75 </p>
76 <p>
77 There are effectively two versions of the <a href="http://en.wikipedia.org/wiki/Gamma_function" target="_top">tgamma</a>
78 function internally: a fully generic version that is slow, but reasonably
79 accurate, and a much more efficient approximation that is used where the
80 number of digits in the significand of T correspond to a certain <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
81 approximation</a>. In practice any built in floating point type you will
82 encounter has an appropriate <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
83 approximation</a> defined for it. It is also possible, given enough machine
84 time, to generate further <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos approximation</a>'s
85 using the program libs/math/tools/lanczos_generator.cpp.
86 </p>
87 <p>
88 The return type of this function is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
89 type calculation rules</em></span></a>: the result is <code class="computeroutput"><span class="keyword">double</span></code>
90 when T is an integer type, and T otherwise.
91 </p>
92 <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>
93 <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">tgamma1pm1</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">dz</span><span class="special">);</span>
94
95 <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>
96 <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">tgamma1pm1</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">dz</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>
97 </pre>
98 <p>
99 Returns <code class="computeroutput"><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">dz</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span></code>.
100 Internally the implementation does not make use of the addition and subtraction
101 implied by the definition, leading to accurate results even for very small
102 <code class="computeroutput"><span class="identifier">dz</span></code>. However, the implementation
103 is capped to either 35 digit accuracy, or to the precision of the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
104 approximation</a> associated with type T, whichever is more accurate.
105 </p>
106 <p>
107 The return type of this function is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
108 type calculation rules</em></span></a>: the result is <code class="computeroutput"><span class="keyword">double</span></code>
109 when T is an integer type, and T otherwise.
110 </p>
111 <p>
112 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
113 be used to control the behaviour of the function: how it handles errors,
114 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
115 documentation for more details</a>.
116 </p>
117 <h5>
118 <a name="math_toolkit.sf_gamma.tgamma.h2"></a>
119 <span class="phrase"><a name="math_toolkit.sf_gamma.tgamma.accuracy"></a></span><a class="link" href="tgamma.html#math_toolkit.sf_gamma.tgamma.accuracy">Accuracy</a>
120 </h5>
121 <p>
122 The following table shows the peak errors (in units of epsilon) found on
123 various platforms with various floating point types, along with comparisons
124 to other common libraries. Unless otherwise specified any floating point
125 type that is narrower than the one shown will have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively
126 zero error</a>.
127 </p>
128 <div class="table">
129 <a name="math_toolkit.sf_gamma.tgamma.table_tgamma"></a><p class="title"><b>Table&#160;6.1.&#160;Error rates for tgamma</b></p>
130 <div class="table-contents"><table class="table" summary="Error rates for tgamma">
131 <colgroup>
132 <col>
133 <col>
134 <col>
135 <col>
136 <col>
137 </colgroup>
138 <thead><tr>
139 <th>
140 </th>
141 <th>
142 <p>
143 Microsoft Visual C++ version 12.0<br> Win32<br> double
144 </p>
145 </th>
146 <th>
147 <p>
148 GNU C++ version 5.1.0<br> linux<br> double
149 </p>
150 </th>
151 <th>
152 <p>
153 GNU C++ version 5.1.0<br> linux<br> long double
154 </p>
155 </th>
156 <th>
157 <p>
158 Sun compiler version 0x5130<br> Sun Solaris<br> long double
159 </p>
160 </th>
161 </tr></thead>
162 <tbody>
163 <tr>
164 <td>
165 <p>
166 factorials
167 </p>
168 </td>
169 <td>
170 <p>
171 <span class="blue">Max = 1.85&#949; (Mean = 0.491&#949;)</span><br> <br>
172 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 3.17&#949; (Mean = 0.928&#949;))
173 </p>
174 </td>
175 <td>
176 <p>
177 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
178 1.16:</em></span> Max = 3.95&#949; (Mean = 0.783&#949;))<br> (<span class="emphasis"><em>Rmath
179 3.0.2:</em></span> Max = 314&#949; (Mean = 93.4&#949;))<br> (<span class="emphasis"><em>Cephes:</em></span>
180 Max = 3.19&#949; (Mean = 0.884&#949;))
181 </p>
182 </td>
183 <td>
184 <p>
185 <span class="blue">Max = 1.96&#949; (Mean = 0.483&#949;)</span><br> <br>
186 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 1.66&#949; (Mean = 0.584&#949;))<br>
187 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.66&#949; (Mean = 0.584&#949;))
188 </p>
189 </td>
190 <td>
191 <p>
192 <span class="blue">Max = 172&#949; (Mean = 41&#949;)</span><br> <br>
193 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0&#949; (Mean = 0&#949;))
194 </p>
195 </td>
196 </tr>
197 <tr>
198 <td>
199 <p>
200 near 0
201 </p>
202 </td>
203 <td>
204 <p>
205 <span class="blue">Max = 1.96&#949; (Mean = 0.684&#949;)</span><br> <br>
206 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1&#949; (Mean = 0.405&#949;))
207 </p>
208 </td>
209 <td>
210 <p>
211 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
212 1.16:</em></span> Max = 4.51&#949; (Mean = 1.92&#949;))<br> (<span class="emphasis"><em>Rmath
213 3.0.2:</em></span> Max = 1&#949; (Mean = 0.335&#949;))<br> (<span class="emphasis"><em>Cephes:</em></span>
214 Max = 1&#949; (Mean = 0.548&#949;))
215 </p>
216 </td>
217 <td>
218 <p>
219 <span class="blue">Max = 2&#949; (Mean = 0.73&#949;)</span><br> <br>
220 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 1&#949; (Mean = 0.376&#949;))<br>
221 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1&#949; (Mean = 0.376&#949;))
222 </p>
223 </td>
224 <td>
225 <p>
226 <span class="blue">Max = 2&#949; (Mean = 0.647&#949;)</span><br> <br>
227 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.5&#949; (Mean = 0.0791&#949;))
228 </p>
229 </td>
230 </tr>
231 <tr>
232 <td>
233 <p>
234 near 1
235 </p>
236 </td>
237 <td>
238 <p>
239 <span class="blue">Max = 2&#949; (Mean = 0.865&#949;)</span><br> <br>
240 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1&#949; (Mean = 0.4&#949;))
241 </p>
242 </td>
243 <td>
244 <p>
245 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
246 1.16:</em></span> Max = 4.41&#949; (Mean = 1.81&#949;))<br> (<span class="emphasis"><em>Rmath
247 3.0.2:</em></span> Max = 1&#949; (Mean = 0.32&#949;))<br> (<span class="emphasis"><em>Cephes:</em></span>
248 Max = 1&#949; (Mean = 0.518&#949;))
249 </p>
250 </td>
251 <td>
252 <p>
253 <span class="blue">Max = 2&#949; (Mean = 0.85&#949;)</span><br> <br>
254 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 0.918&#949; (Mean = 0.203&#949;))<br>
255 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.918&#949; (Mean = 0.203&#949;))
256 </p>
257 </td>
258 <td>
259 <p>
260 <span class="blue">Max = 3.01&#949; (Mean = 1.06&#949;)</span><br> <br>
261 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1&#949; (Mean = 0.175&#949;))
262 </p>
263 </td>
264 </tr>
265 <tr>
266 <td>
267 <p>
268 near 2
269 </p>
270 </td>
271 <td>
272 <p>
273 <span class="blue">Max = 2&#949; (Mean = 0.995&#949;)</span><br> <br>
274 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0&#949; (Mean = 0&#949;))
275 </p>
276 </td>
277 <td>
278 <p>
279 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
280 1.16:</em></span> Max = 7.95&#949; (Mean = 3.12&#949;))<br> (<span class="emphasis"><em>Rmath
281 3.0.2:</em></span> Max = 1&#949; (Mean = 0.191&#949;))<br> (<span class="emphasis"><em>Cephes:</em></span>
282 Max = 1.09&#949; (Mean = 0.502&#949;))
283 </p>
284 </td>
285 <td>
286 <p>
287 <span class="blue">Max = 2&#949; (Mean = 0.913&#949;)</span><br> <br>
288 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 0.558&#949; (Mean = 0.298&#949;))<br>
289 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.558&#949; (Mean = 0.298&#949;))
290 </p>
291 </td>
292 <td>
293 <p>
294 <span class="blue">Max = 5.01&#949; (Mean = 1.89&#949;)</span><br> <br>
295 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0&#949; (Mean = 0&#949;))
296 </p>
297 </td>
298 </tr>
299 <tr>
300 <td>
301 <p>
302 near -10
303 </p>
304 </td>
305 <td>
306 <p>
307 <span class="blue">Max = 1.73&#949; (Mean = 0.729&#949;)</span><br> <br>
308 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.866&#949; (Mean = 0.445&#949;))
309 </p>
310 </td>
311 <td>
312 <p>
313 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
314 1.16:</em></span> Max = 2.6&#949; (Mean = 1.05&#949;))<br> (<span class="emphasis"><em>Rmath
315 3.0.2:</em></span> Max = 6.34e+05&#949; (Mean = 1.2e+05&#949;))<br> (<span class="emphasis"><em>Cephes:</em></span>
316 Max = 2.6&#949; (Mean = 0.956&#949;))
317 </p>
318 </td>
319 <td>
320 <p>
321 <span class="blue">Max = 2.6&#949; (Mean = 0.985&#949;)</span><br> <br>
322 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 2.26&#949; (Mean = 1.08&#949;))<br>
323 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 2.26&#949; (Mean = 1.08&#949;))
324 </p>
325 </td>
326 <td>
327 <p>
328 <span class="blue">Max = 1.75&#949; (Mean = 0.819&#949;)</span><br> <br>
329 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0&#949; (Mean = 0&#949;))
330 </p>
331 </td>
332 </tr>
333 <tr>
334 <td>
335 <p>
336 near -55
337 </p>
338 </td>
339 <td>
340 <p>
341 <span class="blue">Max = 1.8&#949; (Mean = 0.817&#949;)</span><br> <br>
342 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 3.87e+004&#949; (Mean = 6.71e+003&#949;))
343 </p>
344 </td>
345 <td>
346 <p>
347 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
348 1.16:</em></span> Max = 1.8&#949; (Mean = 0.782&#949;))<br> (<span class="emphasis"><em>Rmath
349 3.0.2:</em></span> Max = 6.36e+06&#949; (Mean = 1.13e+06&#949;))<br> (<span class="emphasis"><em>Cephes:</em></span>
350 Max = 2.7&#949; (Mean = 0.988&#949;))
351 </p>
352 </td>
353 <td>
354 <p>
355 <span class="blue">Max = 1.8&#949; (Mean = 0.847&#949;)</span><br> <br>
356 (<span class="emphasis"><em>&lt;tr1/cmath&gt;:</em></span> Max = 1.79&#949; (Mean = 0.75&#949;))<br>
357 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.79&#949; (Mean = 0.75&#949;))
358 </p>
359 </td>
360 <td>
361 <p>
362 <span class="blue">Max = 98.5&#949; (Mean = 53.4&#949;)</span><br> <br>
363 (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0&#949; (Mean = 0&#949;))
364 </p>
365 </td>
366 </tr>
367 </tbody>
368 </table></div>
369 </div>
370 <br class="table-break"><div class="table">
371 <a name="math_toolkit.sf_gamma.tgamma.table_tgamma1pm1"></a><p class="title"><b>Table&#160;6.2.&#160;Error rates for tgamma1pm1</b></p>
372 <div class="table-contents"><table class="table" summary="Error rates for tgamma1pm1">
373 <colgroup>
374 <col>
375 <col>
376 <col>
377 <col>
378 <col>
379 </colgroup>
380 <thead><tr>
381 <th>
382 </th>
383 <th>
384 <p>
385 Microsoft Visual C++ version 12.0<br> Win32<br> double
386 </p>
387 </th>
388 <th>
389 <p>
390 GNU C++ version 5.1.0<br> linux<br> double
391 </p>
392 </th>
393 <th>
394 <p>
395 GNU C++ version 5.1.0<br> linux<br> long double
396 </p>
397 </th>
398 <th>
399 <p>
400 Sun compiler version 0x5130<br> Sun Solaris<br> long double
401 </p>
402 </th>
403 </tr></thead>
404 <tbody><tr>
405 <td>
406 <p>
407 tgamma1pm1(dz)
408 </p>
409 </td>
410 <td>
411 <p>
412 <span class="blue">Max = 0.982&#949; (Mean = 0.399&#949;)</span>
413 </p>
414 </td>
415 <td>
416 <p>
417 <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span>
418 </p>
419 </td>
420 <td>
421 <p>
422 <span class="blue">Max = 1.12&#949; (Mean = 0.49&#949;)</span>
423 </p>
424 </td>
425 <td>
426 <p>
427 <span class="blue">Max = 3.97&#949; (Mean = 0.713&#949;)</span>
428 </p>
429 </td>
430 </tr></tbody>
431 </table></div>
432 </div>
433 <br class="table-break"><h5>
434 <a name="math_toolkit.sf_gamma.tgamma.h3"></a>
435 <span class="phrase"><a name="math_toolkit.sf_gamma.tgamma.testing"></a></span><a class="link" href="tgamma.html#math_toolkit.sf_gamma.tgamma.testing">Testing</a>
436 </h5>
437 <p>
438 The gamma is relatively easy to test: factorials and half-integer factorials
439 can be calculated exactly by other means and compared with the gamma function.
440 In addition, some accuracy tests in known tricky areas were computed at high
441 precision using the generic version of this function.
442 </p>
443 <p>
444 The function <code class="computeroutput"><span class="identifier">tgamma1pm1</span></code> is
445 tested against values calculated very naively using the formula <code class="computeroutput"><span class="identifier">tgamma</span><span class="special">(</span><span class="number">1</span><span class="special">+</span><span class="identifier">dz</span><span class="special">)-</span><span class="number">1</span></code> with a
446 lanczos approximation accurate to around 100 decimal digits.
447 </p>
448 <h5>
449 <a name="math_toolkit.sf_gamma.tgamma.h4"></a>
450 <span class="phrase"><a name="math_toolkit.sf_gamma.tgamma.implementation"></a></span><a class="link" href="tgamma.html#math_toolkit.sf_gamma.tgamma.implementation">Implementation</a>
451 </h5>
452 <p>
453 The generic version of the <code class="computeroutput"><span class="identifier">tgamma</span></code>
454 function is implemented Sterling's approximation for lgamma for large z:
455 </p>
456 <p>
457 <span class="inlinemediaobject"><img src="../../../equations/gamma6.svg"></span>
458 </p>
459 <p>
460 Following exponentiation, downward recursion is then used for small values
461 of z.
462 </p>
463 <p>
464 For types of known precision the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
465 approximation</a> is used, a traits class <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">lanczos</span><span class="special">::</span><span class="identifier">lanczos_traits</span></code>
466 maps type T to an appropriate approximation.
467 </p>
468 <p>
469 For z in the range -20 &lt; z &lt; 1 then recursion is used to shift to z
470 &gt; 1 via:
471 </p>
472 <p>
473 <span class="inlinemediaobject"><img src="../../../equations/gamm3.svg"></span>
474 </p>
475 <p>
476 For very small z, this helps to preserve the identity:
477 </p>
478 <p>
479 <span class="inlinemediaobject"><img src="../../../equations/gamm4.svg"></span>
480 </p>
481 <p>
482 For z &lt; -20 the reflection formula:
483 </p>
484 <p>
485 <span class="inlinemediaobject"><img src="../../../equations/gamm5.svg"></span>
486 </p>
487 <p>
488 is used. Particular care has to be taken to evaluate the <code class="literal">z * sin(&#960; &#160; *
489 z)</code> part: a special routine is used to reduce z prior to multiplying
490 by &#960; &#160; to ensure that the result in is the range [0, &#960;/2]. Without this an excessive
491 amount of error occurs in this region (which is hard enough already, as the
492 rate of change near a negative pole is <span class="emphasis"><em>exceptionally</em></span>
493 high).
494 </p>
495 <p>
496 Finally if the argument is a small integer then table lookup of the factorial
497 is used.
498 </p>
499 <p>
500 The function <code class="computeroutput"><span class="identifier">tgamma1pm1</span></code> is
501 implemented using rational approximations <a class="link" href="../sf_implementation.html#math_toolkit.sf_implementation.rational_approximations_used">devised
502 by JM</a> in the region <code class="computeroutput"><span class="special">-</span><span class="number">0.5</span> <span class="special">&lt;</span> <span class="identifier">dz</span>
503 <span class="special">&lt;</span> <span class="number">2</span></code>.
504 These are the same approximations (and internal routines) that are used for
505 <a class="link" href="lgamma.html" title="Log Gamma">lgamma</a>, and so aren't
506 detailed further here. The result of the approximation is <code class="computeroutput"><span class="identifier">log</span><span class="special">(</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">dz</span><span class="special">+</span><span class="number">1</span><span class="special">))</span></code> which can
507 fed into <a class="link" href="../powers/expm1.html" title="expm1">expm1</a> to give the
508 desired result. Outside the range <code class="computeroutput"><span class="special">-</span><span class="number">0.5</span> <span class="special">&lt;</span> <span class="identifier">dz</span>
509 <span class="special">&lt;</span> <span class="number">2</span></code>
510 then the naive formula <code class="computeroutput"><span class="identifier">tgamma1pm1</span><span class="special">(</span><span class="identifier">dz</span><span class="special">)</span>
511 <span class="special">=</span> <span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">dz</span><span class="special">+</span><span class="number">1</span><span class="special">)-</span><span class="number">1</span></code>
512 can be used directly.
513 </p>
514 </div>
515 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
516 <td align="left"></td>
517 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
518 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
519 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;de, Gautam Sewani,
520 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
521 Distributed under the Boost Software License, Version 1.0. (See accompanying
522 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>)
523 </p>
524 </div></td>
525 </tr></table>
526 <hr>
527 <div class="spirit-nav">
528 <a accesskey="p" href="../sf_gamma.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_gamma.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="lgamma.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
529 </div>
530 </body>
531 </html>