<title>Gamma</title>
<link rel="stylesheet" href="../../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
-<link rel="home" href="../../index.html" title="Math Toolkit 2.10.0">
+<link rel="home" href="../../index.html" title="Math Toolkit 2.11.0">
<link rel="up" href="../sf_gamma.html" title="Gamma Functions">
<link rel="prev" href="../sf_gamma.html" title="Gamma Functions">
<link rel="next" href="lgamma.html" title="Log Gamma">
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
<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">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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
-<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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
<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">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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
-<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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<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>
<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">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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
-<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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
</pre>
<p>
Returns the "true gamma" (hence name tgamma) of value z:
</p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../equations/gamm1.svg"></span>
+
+ </p></blockquote></div>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../graphs/tgamma.svg" align="middle"></span>
+
+ </p></blockquote></div>
<p>
- <span class="inlinemediaobject"><img src="../../../equations/gamm1.svg"></span>
- </p>
-<p>
- <span class="inlinemediaobject"><img src="../../../graphs/tgamma.svg" align="middle"></span>
- </p>
-<p>
- The final <a class="link" href="../../policy.html" title="Chapter 19. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
+ The final <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
be used to control the behaviour of the function: how it handles errors,
- what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 19. Policies: Controlling Precision, Error Handling etc">policy
+ what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">policy
documentation for more details</a>.
</p>
<p>
- There are effectively two versions of the <a href="http://en.wikipedia.org/wiki/Gamma_function" target="_top">tgamma</a>
- function internally: a fully generic version that is slow, but reasonably
- accurate, and a much more efficient approximation that is used where the
- number of digits in the significand of T correspond to a certain <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
- approximation</a>. In practice any built in floating point type you will
- encounter has an appropriate <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
- approximation</a> defined for it. It is also possible, given enough machine
- time, to generate further <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos approximation</a>'s
- using the program libs/math/tools/lanczos_generator.cpp.
- </p>
-<p>
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
type calculation rules</em></span></a>: the result is <code class="computeroutput"><span class="keyword">double</span></code>
when T is an integer type, and T otherwise.
<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>
<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">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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
-<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 19. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
+<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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
</pre>
<p>
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>.
Internally the implementation does not make use of the addition and subtraction
implied by the definition, leading to accurate results even for very small
- <code class="computeroutput"><span class="identifier">dz</span></code>. However, the implementation
- is capped to either 35 digit accuracy, or to the precision of the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
- approximation</a> associated with type T, whichever is more accurate.
+ <code class="computeroutput"><span class="identifier">dz</span></code>.
</p>
<p>
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
when T is an integer type, and T otherwise.
</p>
<p>
- The final <a class="link" href="../../policy.html" title="Chapter 19. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
+ The final <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
be used to control the behaviour of the function: how it handles errors,
- what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 19. Policies: Controlling Precision, Error Handling etc">policy
+ what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">policy
documentation for more details</a>.
</p>
<h5>
zero error</a>.
</p>
<div class="table">
-<a name="math_toolkit.sf_gamma.tgamma.table_tgamma"></a><p class="title"><b>Table 7.1. Error rates for tgamma</b></p>
+<a name="math_toolkit.sf_gamma.tgamma.table_tgamma"></a><p class="title"><b>Table 8.1. Error rates for tgamma</b></p>
<div class="table-contents"><table class="table" summary="Error rates for tgamma">
<colgroup>
<col>
</table></div>
</div>
<br class="table-break"><div class="table">
-<a name="math_toolkit.sf_gamma.tgamma.table_tgamma1pm1"></a><p class="title"><b>Table 7.2. Error rates for tgamma1pm1</b></p>
+<a name="math_toolkit.sf_gamma.tgamma.table_tgamma1pm1"></a><p class="title"><b>Table 8.2. Error rates for tgamma1pm1</b></p>
<div class="table-contents"><table class="table" summary="Error rates for tgamma1pm1">
<colgroup>
<col>
precision, and GCC-7.1/Ubuntu for <code class="computeroutput"><span class="keyword">long</span>
<span class="keyword">double</span></code> and <code class="computeroutput"><span class="identifier">__float128</span></code>.
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../../graphs/tgamma__double.svg" align="middle"></span>
- </p>
-<p>
- <span class="inlinemediaobject"><img src="../../../graphs/tgamma__80_bit_long_double.svg" align="middle"></span>
- </p>
-<p>
- <span class="inlinemediaobject"><img src="../../../graphs/tgamma____float128.svg" align="middle"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../graphs/tgamma__double.svg" align="middle"></span>
+
+ </p></blockquote></div>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../graphs/tgamma__80_bit_long_double.svg" align="middle"></span>
+
+ </p></blockquote></div>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../graphs/tgamma____float128.svg" align="middle"></span>
+
+ </p></blockquote></div>
<h5>
<a name="math_toolkit.sf_gamma.tgamma.h3"></a>
<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>
</h5>
<p>
The generic version of the <code class="computeroutput"><span class="identifier">tgamma</span></code>
- function is implemented Sterling's approximation for lgamma for large z:
- </p>
-<p>
- <span class="inlinemediaobject"><img src="../../../equations/gamma6.svg"></span>
+ function is implemented Sterling's approximation for <code class="computeroutput"><span class="identifier">lgamma</span></code>
+ for large z:
</p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../equations/gamma6.svg"></span>
+
+ </p></blockquote></div>
<p>
Following exponentiation, downward recursion is then used for small values
of z.
For z in the range -20 < z < 1 then recursion is used to shift to z
> 1 via:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../../equations/gamm3.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../equations/gamm3.svg"></span>
+
+ </p></blockquote></div>
<p>
For very small z, this helps to preserve the identity:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../../equations/gamm4.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../equations/gamm4.svg"></span>
+
+ </p></blockquote></div>
<p>
For z < -20 the reflection formula:
</p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../../equations/gamm5.svg"></span>
+
+ </p></blockquote></div>
<p>
- <span class="inlinemediaobject"><img src="../../../equations/gamm5.svg"></span>
- </p>
-<p>
- is used. Particular care has to be taken to evaluate the <code class="literal">z * sin(π   *
+ is used. Particular care has to be taken to evaluate the <code class="literal">z * sin(π *
z)</code> part: a special routine is used to reduce z prior to multiplying
- by π   to ensure that the result in is the range [0, π/2]. Without this an excessive
+ by π to ensure that the result in is the range [0, π/2]. Without this an excessive
amount of error occurs in this region (which is hard enough already, as the
rate of change near a negative pole is <span class="emphasis"><em>exceptionally</em></span>
high).