tgamma.html 31 KB

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