1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Gamma</title> 5<link rel="stylesheet" href="../../math.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Math Toolkit 2.12.0"> 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"><</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">></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"><</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">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"><</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 21. 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">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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 42 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">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"><</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 21. 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">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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</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"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></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"><</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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 60</pre> 61<p> 62 Returns the "true gamma" (hence name tgamma) of value z: 63 </p> 64<div class="blockquote"><blockquote class="blockquote"><p> 65 <span class="inlinemediaobject"><img src="../../../equations/gamm1.svg"></span> 66 67 </p></blockquote></div> 68<div class="blockquote"><blockquote class="blockquote"><p> 69 <span class="inlinemediaobject"><img src="../../../graphs/tgamma.svg" align="middle"></span> 70 71 </p></blockquote></div> 72<p> 73 The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can 74 be used to control the behaviour of the function: how it handles errors, 75 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy 76 documentation for more details</a>. 77 </p> 78<p> 79 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 80 type calculation rules</em></span></a>: the result is <code class="computeroutput"><span class="keyword">double</span></code> 81 when T is an integer type, and T otherwise. 82 </p> 83<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> 84<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> 85 86<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> 87<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 88</pre> 89<p> 90 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>. 91 Internally the implementation does not make use of the addition and subtraction 92 implied by the definition, leading to accurate results even for very small 93 <code class="computeroutput"><span class="identifier">dz</span></code>. 94 </p> 95<p> 96 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 97 type calculation rules</em></span></a>: the result is <code class="computeroutput"><span class="keyword">double</span></code> 98 when T is an integer type, and T otherwise. 99 </p> 100<p> 101 The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can 102 be used to control the behaviour of the function: how it handles errors, 103 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy 104 documentation for more details</a>. 105 </p> 106<h5> 107<a name="math_toolkit.sf_gamma.tgamma.h2"></a> 108 <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> 109 </h5> 110<p> 111 The following table shows the peak errors (in units of epsilon) found on 112 various platforms with various floating point types, along with comparisons 113 to other common libraries. Unless otherwise specified any floating point 114 type that is narrower than the one shown will have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively 115 zero error</a>. 116 </p> 117<div class="table"> 118<a name="math_toolkit.sf_gamma.tgamma.table_tgamma"></a><p class="title"><b>Table 8.1. Error rates for tgamma</b></p> 119<div class="table-contents"><table class="table" summary="Error rates for tgamma"> 120<colgroup> 121<col> 122<col> 123<col> 124<col> 125<col> 126</colgroup> 127<thead><tr> 128<th> 129 </th> 130<th> 131 <p> 132 GNU C++ version 7.1.0<br> linux<br> double 133 </p> 134 </th> 135<th> 136 <p> 137 GNU C++ version 7.1.0<br> linux<br> long double 138 </p> 139 </th> 140<th> 141 <p> 142 Sun compiler version 0x5150<br> Sun Solaris<br> long double 143 </p> 144 </th> 145<th> 146 <p> 147 Microsoft Visual C++ version 14.1<br> Win32<br> double 148 </p> 149 </th> 150</tr></thead> 151<tbody> 152<tr> 153<td> 154 <p> 155 factorials 156 </p> 157 </td> 158<td> 159 <p> 160 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 161 2.1:</em></span> Max = 3.95ε (Mean = 0.783ε))<br> (<span class="emphasis"><em>Rmath 162 3.2.3:</em></span> Max = 314ε (Mean = 93.4ε)) 163 </p> 164 </td> 165<td> 166 <p> 167 <span class="blue">Max = 2.67ε (Mean = 0.617ε)</span><br> <br> 168 (<span class="emphasis"><em><cmath>:</em></span> Max = 1.66ε (Mean = 0.584ε))<br> 169 (<span class="emphasis"><em><math.h>:</em></span> Max = 1.66ε (Mean = 0.584ε)) 170 </p> 171 </td> 172<td> 173 <p> 174 <span class="blue">Max = 172ε (Mean = 41ε)</span><br> <br> 175 (<span class="emphasis"><em><math.h>:</em></span> Max = 0ε (Mean = 0ε)) 176 </p> 177 </td> 178<td> 179 <p> 180 <span class="blue">Max = 1.85ε (Mean = 0.566ε)</span><br> <br> 181 (<span class="emphasis"><em><math.h>:</em></span> Max = 3.17ε (Mean = 0.928ε)) 182 </p> 183 </td> 184</tr> 185<tr> 186<td> 187 <p> 188 near 0 189 </p> 190 </td> 191<td> 192 <p> 193 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 194 2.1:</em></span> Max = 4.51ε (Mean = 1.92ε))<br> (<span class="emphasis"><em>Rmath 195 3.2.3:</em></span> Max = 1ε (Mean = 0.335ε)) 196 </p> 197 </td> 198<td> 199 <p> 200 <span class="blue">Max = 2ε (Mean = 0.608ε)</span><br> <br> 201 (<span class="emphasis"><em><cmath>:</em></span> Max = 1ε (Mean = 0.376ε))<br> 202 (<span class="emphasis"><em><math.h>:</em></span> Max = 1ε (Mean = 0.376ε)) 203 </p> 204 </td> 205<td> 206 <p> 207 <span class="blue">Max = 2ε (Mean = 0.647ε)</span><br> <br> 208 (<span class="emphasis"><em><math.h>:</em></span> Max = 0.5ε (Mean = 0.0791ε)) 209 </p> 210 </td> 211<td> 212 <p> 213 <span class="blue">Max = 1.5ε (Mean = 0.635ε)</span><br> <br> 214 (<span class="emphasis"><em><math.h>:</em></span> Max = 1ε (Mean = 0.405ε)) 215 </p> 216 </td> 217</tr> 218<tr> 219<td> 220 <p> 221 near 1 222 </p> 223 </td> 224<td> 225 <p> 226 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 227 2.1:</em></span> Max = 4.41ε (Mean = 1.81ε))<br> (<span class="emphasis"><em>Rmath 228 3.2.3:</em></span> Max = 1ε (Mean = 0.32ε)) 229 </p> 230 </td> 231<td> 232 <p> 233 <span class="blue">Max = 2.51ε (Mean = 1.02ε)</span><br> <br> 234 (<span class="emphasis"><em><cmath>:</em></span> Max = 0.918ε (Mean = 0.203ε))<br> 235 (<span class="emphasis"><em><math.h>:</em></span> Max = 0.918ε (Mean = 0.203ε)) 236 </p> 237 </td> 238<td> 239 <p> 240 <span class="blue">Max = 3.01ε (Mean = 1.06ε)</span><br> <br> 241 (<span class="emphasis"><em><math.h>:</em></span> Max = 1ε (Mean = 0.175ε)) 242 </p> 243 </td> 244<td> 245 <p> 246 <span class="blue">Max = 1.1ε (Mean = 0.59ε)</span><br> <br> 247 (<span class="emphasis"><em><math.h>:</em></span> Max = 1ε (Mean = 0.4ε)) 248 </p> 249 </td> 250</tr> 251<tr> 252<td> 253 <p> 254 near 2 255 </p> 256 </td> 257<td> 258 <p> 259 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 260 2.1:</em></span> Max = 7.95ε (Mean = 3.12ε))<br> (<span class="emphasis"><em>Rmath 261 3.2.3:</em></span> Max = 1ε (Mean = 0.191ε)) 262 </p> 263 </td> 264<td> 265 <p> 266 <span class="blue">Max = 4.1ε (Mean = 1.55ε)</span><br> <br> 267 (<span class="emphasis"><em><cmath>:</em></span> Max = 0.558ε (Mean = 0.298ε))<br> 268 (<span class="emphasis"><em><math.h>:</em></span> Max = 0.558ε (Mean = 0.298ε)) 269 </p> 270 </td> 271<td> 272 <p> 273 <span class="blue">Max = 5.01ε (Mean = 1.89ε)</span><br> <br> 274 (<span class="emphasis"><em><math.h>:</em></span> Max = 0ε (Mean = 0ε)) 275 </p> 276 </td> 277<td> 278 <p> 279 <span class="blue">Max = 2ε (Mean = 0.733ε)</span><br> <br> 280 (<span class="emphasis"><em><math.h>:</em></span> Max = 0ε (Mean = 0ε)) 281 </p> 282 </td> 283</tr> 284<tr> 285<td> 286 <p> 287 near -10 288 </p> 289 </td> 290<td> 291 <p> 292 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 293 2.1:</em></span> Max = 2.6ε (Mean = 1.05ε))<br> (<span class="emphasis"><em>Rmath 294 3.2.3:</em></span> Max = 34.9ε (Mean = 9.2ε)) 295 </p> 296 </td> 297<td> 298 <p> 299 <span class="blue">Max = 1.75ε (Mean = 0.895ε)</span><br> <br> 300 (<span class="emphasis"><em><cmath>:</em></span> Max = 2.26ε (Mean = 1.08ε))<br> 301 (<span class="emphasis"><em><math.h>:</em></span> Max = 2.26ε (Mean = 1.08ε)) 302 </p> 303 </td> 304<td> 305 <p> 306 <span class="blue">Max = 1.75ε (Mean = 0.819ε)</span><br> <br> 307 (<span class="emphasis"><em><math.h>:</em></span> Max = 0ε (Mean = 0ε)) 308 </p> 309 </td> 310<td> 311 <p> 312 <span class="blue">Max = 1.86ε (Mean = 0.881ε)</span><br> <br> 313 (<span class="emphasis"><em><math.h>:</em></span> Max = 0.866ε (Mean = 0.445ε)) 314 </p> 315 </td> 316</tr> 317<tr> 318<td> 319 <p> 320 near -55 321 </p> 322 </td> 323<td> 324 <p> 325 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 326 2.1:</em></span> Max = 1.8ε (Mean = 0.782ε))<br> (<span class="emphasis"><em>Rmath 327 3.2.3:</em></span> Max = 3.89e+04ε (Mean = 9.52e+03ε)) 328 </p> 329 </td> 330<td> 331 <p> 332 <span class="blue">Max = 2.69ε (Mean = 1.09ε)</span><br> <br> 333 (<span class="emphasis"><em><cmath>:</em></span> Max = 1.79ε (Mean = 0.75ε))<br> 334 (<span class="emphasis"><em><math.h>:</em></span> Max = 1.79ε (Mean = 0.75ε)) 335 </p> 336 </td> 337<td> 338 <p> 339 <span class="blue">Max = 98.5ε (Mean = 53.4ε)</span><br> <br> 340 (<span class="emphasis"><em><math.h>:</em></span> Max = 0ε (Mean = 0ε)) 341 </p> 342 </td> 343<td> 344 <p> 345 <span class="blue">Max = 2.7ε (Mean = 1.35ε)</span><br> <br> 346 (<span class="emphasis"><em><math.h>:</em></span> Max = 3.87e+04ε (Mean = 6.71e+03ε)) 347 </p> 348 </td> 349</tr> 350</tbody> 351</table></div> 352</div> 353<br class="table-break"><div class="table"> 354<a name="math_toolkit.sf_gamma.tgamma.table_tgamma1pm1"></a><p class="title"><b>Table 8.2. Error rates for tgamma1pm1</b></p> 355<div class="table-contents"><table class="table" summary="Error rates for tgamma1pm1"> 356<colgroup> 357<col> 358<col> 359<col> 360<col> 361<col> 362</colgroup> 363<thead><tr> 364<th> 365 </th> 366<th> 367 <p> 368 GNU C++ version 7.1.0<br> linux<br> double 369 </p> 370 </th> 371<th> 372 <p> 373 GNU C++ version 7.1.0<br> linux<br> long double 374 </p> 375 </th> 376<th> 377 <p> 378 Sun compiler version 0x5150<br> Sun Solaris<br> long double 379 </p> 380 </th> 381<th> 382 <p> 383 Microsoft Visual C++ version 14.1<br> Win32<br> double 384 </p> 385 </th> 386</tr></thead> 387<tbody><tr> 388<td> 389 <p> 390 tgamma1pm1(dz) 391 </p> 392 </td> 393<td> 394 <p> 395 <span class="blue">Max = 0ε (Mean = 0ε)</span> 396 </p> 397 </td> 398<td> 399 <p> 400 <span class="blue">Max = 1.12ε (Mean = 0.49ε)</span> 401 </p> 402 </td> 403<td> 404 <p> 405 <span class="blue">Max = 6.61ε (Mean = 0.84ε)</span> 406 </p> 407 </td> 408<td> 409 <p> 410 <span class="blue">Max = 3.31ε (Mean = 0.517ε)</span> 411 </p> 412 </td> 413</tr></tbody> 414</table></div> 415</div> 416<br class="table-break"><p> 417 The following error plot are based on an exhaustive search of the functions 418 domain, MSVC-15.5 at <code class="computeroutput"><span class="keyword">double</span></code> 419 precision, and GCC-7.1/Ubuntu for <code class="computeroutput"><span class="keyword">long</span> 420 <span class="keyword">double</span></code> and <code class="computeroutput"><span class="identifier">__float128</span></code>. 421 </p> 422<div class="blockquote"><blockquote class="blockquote"><p> 423 <span class="inlinemediaobject"><img src="../../../graphs/tgamma__double.svg" align="middle"></span> 424 425 </p></blockquote></div> 426<div class="blockquote"><blockquote class="blockquote"><p> 427 <span class="inlinemediaobject"><img src="../../../graphs/tgamma__80_bit_long_double.svg" align="middle"></span> 428 429 </p></blockquote></div> 430<div class="blockquote"><blockquote class="blockquote"><p> 431 <span class="inlinemediaobject"><img src="../../../graphs/tgamma____float128.svg" align="middle"></span> 432 433 </p></blockquote></div> 434<h5> 435<a name="math_toolkit.sf_gamma.tgamma.h3"></a> 436 <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> 437 </h5> 438<p> 439 The gamma is relatively easy to test: factorials and half-integer factorials 440 can be calculated exactly by other means and compared with the gamma function. 441 In addition, some accuracy tests in known tricky areas were computed at high 442 precision using the generic version of this function. 443 </p> 444<p> 445 The function <code class="computeroutput"><span class="identifier">tgamma1pm1</span></code> is 446 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 447 lanczos approximation accurate to around 100 decimal digits. 448 </p> 449<h5> 450<a name="math_toolkit.sf_gamma.tgamma.h4"></a> 451 <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> 452 </h5> 453<p> 454 The generic version of the <code class="computeroutput"><span class="identifier">tgamma</span></code> 455 function is implemented Sterling's approximation for <code class="computeroutput"><span class="identifier">lgamma</span></code> 456 for large z: 457 </p> 458<div class="blockquote"><blockquote class="blockquote"><p> 459 <span class="inlinemediaobject"><img src="../../../equations/gamma6.svg"></span> 460 461 </p></blockquote></div> 462<p> 463 Following exponentiation, downward recursion is then used for small values 464 of z. 465 </p> 466<p> 467 For types of known precision the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos 468 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> 469 maps type T to an appropriate approximation. 470 </p> 471<p> 472 For z in the range -20 < z < 1 then recursion is used to shift to z 473 > 1 via: 474 </p> 475<div class="blockquote"><blockquote class="blockquote"><p> 476 <span class="inlinemediaobject"><img src="../../../equations/gamm3.svg"></span> 477 478 </p></blockquote></div> 479<p> 480 For very small z, this helps to preserve the identity: 481 </p> 482<div class="blockquote"><blockquote class="blockquote"><p> 483 <span class="inlinemediaobject"><img src="../../../equations/gamm4.svg"></span> 484 485 </p></blockquote></div> 486<p> 487 For z < -20 the reflection formula: 488 </p> 489<div class="blockquote"><blockquote class="blockquote"><p> 490 <span class="inlinemediaobject"><img src="../../../equations/gamm5.svg"></span> 491 492 </p></blockquote></div> 493<p> 494 is used. Particular care has to be taken to evaluate the <code class="literal">z * sin(π * 495 z)</code> part: a special routine is used to reduce z prior to multiplying 496 by π to ensure that the result in is the range [0, π/2]. Without this an excessive 497 amount of error occurs in this region (which is hard enough already, as the 498 rate of change near a negative pole is <span class="emphasis"><em>exceptionally</em></span> 499 high). 500 </p> 501<p> 502 Finally if the argument is a small integer then table lookup of the factorial 503 is used. 504 </p> 505<p> 506 The function <code class="computeroutput"><span class="identifier">tgamma1pm1</span></code> is 507 implemented using rational approximations <a class="link" href="../sf_implementation.html#math_toolkit.sf_implementation.rational_approximations_used">devised 508 by JM</a> in the region <code class="computeroutput"><span class="special">-</span><span class="number">0.5</span> <span class="special"><</span> <span class="identifier">dz</span> 509 <span class="special"><</span> <span class="number">2</span></code>. 510 These are the same approximations (and internal routines) that are used for 511 <a class="link" href="lgamma.html" title="Log Gamma">lgamma</a>, and so aren't 512 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 513 fed into <a class="link" href="../powers/expm1.html" title="expm1">expm1</a> to give the 514 desired result. Outside the range <code class="computeroutput"><span class="special">-</span><span class="number">0.5</span> <span class="special"><</span> <span class="identifier">dz</span> 515 <span class="special"><</span> <span class="number">2</span></code> 516 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> 517 <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> 518 can be used directly. 519 </p> 520</div> 521<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 522<td align="left"></td> 523<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 524 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 525 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 526 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 527 Daryle Walker and Xiaogang Zhang<p> 528 Distributed under the Boost Software License, Version 1.0. (See accompanying 529 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>) 530 </p> 531</div></td> 532</tr></table> 533<hr> 534<div class="spirit-nav"> 535<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> 536</div> 537</body> 538</html> 539