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