| <html lang="en"> |
| <head> |
| <title>gamma - Untitled</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="Untitled"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Math.html#Math" title="Math"> |
| <link rel="prev" href="frexp.html#frexp" title="frexp"> |
| <link rel="next" href="hypot.html#hypot" title="hypot"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="gamma"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="hypot.html#hypot">hypot</a>, |
| Previous: <a rel="previous" accesskey="p" href="frexp.html#frexp">frexp</a>, |
| Up: <a rel="up" accesskey="u" href="Math.html#Math">Math</a> |
| <hr> |
| </div> |
| |
| <h3 class="section">1.26 <code>gamma</code>, <code>gammaf</code>, <code>lgamma</code>, <code>lgammaf</code>, <code>gamma_r</code>, <code>gammaf_r</code>, <code>lgamma_r</code>, <code>lgammaf_r</code>, <code>tgamma</code>, and <code>tgammaf</code>–logarithmic and plain gamma functions</h3> |
| |
| <p><a name="index-gamma-63"></a><a name="index-gammaf-64"></a><a name="index-lgamma-65"></a><a name="index-lgammaf-66"></a><a name="index-gamma_005fr-67"></a><a name="index-gammaf_005fr-68"></a><a name="index-lgamma_005fr-69"></a><a name="index-lgammaf_005fr-70"></a><a name="index-tgamma-71"></a><a name="index-tgammaf-72"></a><strong>Synopsis</strong> |
| <pre class="example"> #include <math.h> |
| double gamma(double <var>x</var>); |
| float gammaf(float <var>x</var>); |
| double lgamma(double <var>x</var>); |
| float lgammaf(float <var>x</var>); |
| double gamma_r(double <var>x</var>, int *<var>signgamp</var>); |
| float gammaf_r(float <var>x</var>, int *<var>signgamp</var>); |
| double lgamma_r(double <var>x</var>, int *<var>signgamp</var>); |
| float lgammaf_r(float <var>x</var>, int *<var>signgamp</var>); |
| double tgamma(double <var>x</var>); |
| float tgammaf(float <var>x</var>); |
| |
| </pre> |
| <p><strong>Description</strong><br> |
| <code>gamma</code> calculates |
| the natural logarithm of the gamma function of <var>x</var>. The gamma function |
| (<code>exp(gamma(</code><var>x</var><code>))</code>) is a generalization of factorial, and retains |
| the property that |
| <code>exp(gamma(N))</code> is equivalent to <code>N*exp(gamma(N-1))</code>. |
| Accordingly, the results of the gamma function itself grow very |
| quickly. <code>gamma</code> is defined as |
| the natural log of the gamma function, rather than the gamma function |
| itself, |
| to extend the useful range of results representable. |
| |
| <p>The sign of the result is returned in the global variable <code>signgam</code>, |
| which is declared in math.h. |
| |
| <p><code>gammaf</code> performs the same calculation as <code>gamma</code>, but uses and |
| returns <code>float</code> values. |
| |
| <p><code>lgamma</code> and <code>lgammaf</code> are alternate names for <code>gamma</code> and |
| <code>gammaf</code>. The use of <code>lgamma</code> instead of <code>gamma</code> is a reminder |
| that these functions compute the log of the gamma function, rather |
| than the gamma function itself. |
| |
| <p>The functions <code>gamma_r</code>, <code>gammaf_r</code>, <code>lgamma_r</code>, and |
| <code>lgammaf_r</code> are just like <code>gamma</code>, <code>gammaf</code>, <code>lgamma</code>, and |
| <code>lgammaf</code>, respectively, but take an additional argument. This |
| additional argument is a pointer to an integer. This additional |
| argument is used to return the sign of the result, and the global |
| variable <code>signgam</code> is not used. These functions may be used for |
| reentrant calls (but they will still set the global variable <code>errno</code> |
| if an error occurs). |
| |
| <p><code>tgamma</code> and <code>tgammaf</code> are the "true gamma" functions, returning |
| the gamma function of <var>x</var>–without a logarithm. |
| (They are apparently so named because of the prior existence of the old, |
| poorly-named <code>gamma</code> functions which returned the log of gamma up |
| through BSD 4.2.) |
| |
| <p><br> |
| <strong>Returns</strong><br> |
| Normally, the computed result is returned. |
| |
| <p>When <var>x</var> is a nonpositive integer, <code>gamma</code> returns <code>HUGE_VAL</code> |
| and <code>errno</code> is set to <code>EDOM</code>. If the result overflows, <code>gamma</code> |
| returns <code>HUGE_VAL</code> and <code>errno</code> is set to <code>ERANGE</code>. |
| |
| <p>You can modify this error treatment using <code>matherr</code>. |
| |
| <p><br> |
| <strong>Portability</strong><br> |
| Neither <code>gamma</code> nor <code>gammaf</code> is ANSI C. It is better not to use either |
| of these; use <code>lgamma</code> or <code>tgamma</code> instead.<br> |
| <code>lgamma</code>, <code>lgammaf</code>, <code>tgamma</code>, and <code>tgammaf</code> are nominally C standard |
| in terms of the base return values, although the <code>matherr</code> error-handling |
| is not standard, nor is the <var>signgam</var> global for <code>lgamma</code>. |
| |
| <p><br> |
| |
| </body></html> |
| |