diff options
Diffstat (limited to 'devdocs/c/numeric%2Fmath%2Ftgamma.html')
| -rw-r--r-- | devdocs/c/numeric%2Fmath%2Ftgamma.html | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Fmath%2Ftgamma.html b/devdocs/c/numeric%2Fmath%2Ftgamma.html new file mode 100644 index 00000000..5b7fec6f --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Ftgamma.html @@ -0,0 +1,83 @@ + <h1 id="firstHeading" class="firstHeading">tgamma, tgammaf, tgammal</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><math.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float tgammaf( float arg );</pre> +</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">double tgamma( double arg );</pre> +</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long double tgammal( long double arg );</pre> +</td> <td> (3) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dsc-header"> <th> Defined in header <code><tgmath.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define tgamma( arg )</pre> +</td> <td> (4) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <div class="t-li1"> +<span class="t-li">1-3)</span> Computes the <a href="https://en.wikipedia.org/wiki/Gamma_function" class="extiw" title="enwiki:Gamma function">gamma function</a> of <code>arg</code>.</div> <div class="t-li1"> +<span class="t-li">4)</span> Type-generic macro: If <code>arg</code> has type <code>long double</code>, <code>tgammal</code> is called. Otherwise, if <code>arg</code> has integer type or the type <code>double</code>, <code>tgamma</code> is called. Otherwise, <code>tgammaf</code> is called.</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> floating point value </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>If no errors occur, the value of the gamma function of <code>arg</code>, that is \(\Gamma(\mathtt{arg}) = \displaystyle\int_0^\infty\!\! t^{\mathtt{arg}-1} e^{-t}\, dt\)∫<sub class="t-su t-su-b">∞0</sub><i>t</i><sup class="t-su">arg-1</sup> <i>e</i><sup>-t</sup> d<i>t</i>, is returned.</p> +<p>If a domain error occurs, an implementation-defined value (NaN where supported) is returned.</p> +<p>If a pole error occurs, <code><a href="huge_val" title="c/numeric/math/HUGE VAL">±HUGE_VAL</a></code>, <code>±HUGE_VALF</code>, or <code>±HUGE_VALL</code> is returned.</p> +<p>If a range error due to overflow occurs, <code><a href="huge_val" title="c/numeric/math/HUGE VAL">±HUGE_VAL</a></code>, <code>±HUGE_VALF</code>, or <code>±HUGE_VALL</code> is returned.</p> +<p>If a range error due to underflow occurs, the correct value (after rounding) is returned.</p> +<h3 id="Error_handling"> Error handling</h3> <p>Errors are reported as specified in <a href="math_errhandling" title="c/numeric/math/math errhandling"><code>math_errhandling</code></a>.</p> +<p>If <code>arg</code> is zero or is an integer less than zero, a pole error or a domain error may occur.</p> +<p>If the implementation supports IEEE floating-point arithmetic (IEC 60559):</p> +<ul> +<li> If the argument is ±0, ±∞ is returned and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_DIVBYZERO</a></code> is raised. </li> +<li> If the argument is a negative integer, NaN is returned and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INVALID</a></code> is raised. </li> +<li> If the argument is -∞, NaN is returned and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INVALID</a></code> is raised. </li> +<li> If the argument is +∞, +∞ is returned. </li> +<li> If the argument is NaN, NaN is returned. </li> +</ul> <h3 id="Notes"> Notes</h3> <p>If <code>arg</code> is a natural number, <code>tgamma(arg)</code> is the factorial of <code>arg - 1</code>. Many implementations calculate the exact integer-domain factorial if the argument is a sufficiently small integer.</p> +<p>For IEEE-compatible type <code>double</code>, overflow happens if <code><span class="nu0">0</span> <span class="sy1"><</span> x <span class="sy1"><</span> <span class="nu0">1</span><span class="sy2">/</span><a href="http://en.cppreference.com/w/c/types/limits"><span class="kw378">DBL_MAX</span></a></code> or if <code>x > 171.7</code>.</p> +<p><a rel="nofollow" class="external text" href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/tgamma.html">POSIX requires</a> that a pole error occurs if the argument is zero, but a domain error occurs when the argument is a negative integer. It also specifies that in future, domain errors may be replaced by pole errors for negative integer arguments (in which case the return value in those cases would change from NaN to ±∞).</p> +<p>There is a non-standard function named <code>gamma</code> in various implementations, but its definition is inconsistent. For example, glibc and 4.2BSD version of <code>gamma</code> executes <code>lgamma</code>, but 4.4BSD version of <code>gamma</code> executes <code>tgamma</code>.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> +#include <math.h> +#include <float.h> +#include <errno.h> +#include <fenv.h> +// #pragma STDC FENV_ACCESS ON + +int main(void) +{ + printf("tgamma(10) = %f, 9!=%f\n", tgamma(10), 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9.0); + printf("tgamma(0.5) = %f, sqrt(pi) = %f\n", tgamma(0.5), sqrt(acos(-1))); + + // special values + printf("tgamma(+Inf) = %f\n", tgamma(INFINITY)); + + // error handling + errno = 0; feclearexcept(FE_ALL_EXCEPT); + printf("tgamma(-1) = %f\n", tgamma(-1)); + if (errno == ERANGE) + perror(" errno == ERANGE"); + else + if (errno == EDOM) perror(" errno == EDOM"); + if (fetestexcept(FE_DIVBYZERO)) + puts(" FE_DIVBYZERO raised"); + else if (fetestexcept(FE_INVALID)) + puts(" FE_INVALID raised"); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">tgamma(10) = 362880.000000, 9!=362880.000000 +tgamma(0.5) = 1.772454, sqrt(pi) = 1.772454 +tgamma(+Inf) = inf +tgamma(-1) = nan + errno == EDOM: Numerical argument out of domain + FE_INVALID raised</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.12.8.4 The tgamma functions (p: 250) </li> +<li> 7.25 Type-generic math <tgmath.h> (p: 373-375) </li> +<li> F.10.5.4 The tgamma functions (p: 525) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul> +<li> 7.12.8.4 The tgamma functions (p: 231) </li> +<li> 7.22 Type-generic math <tgmath.h> (p: 335-337) </li> +<li> F.9.5.4 The tgamma functions (p: 462) </li> +</ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="lgamma" title="c/numeric/math/lgamma"> <span class="t-lines"><span>lgamma</span><span>lgammaf</span><span>lgammal</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes natural (base-<i>e</i>) logarithm of the gamma function <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/math/tgamma" title="cpp/numeric/math/tgamma">C++ documentation</a></span> for <code>tgamma</code> </td> +</tr> </table> <h3 id="External_links"> External links</h3> <table> <tr> <td> +<a rel="nofollow" class="external text" href="https://mathworld.wolfram.com/GammaFunction.html">Weisstein, Eric W. "Gamma Function."</a> From MathWorld — A Wolfram Web Resource. </td> +</tr> +</table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/numeric/math/tgamma" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/tgamma</a> + </p> +</div> |
