You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
6.9KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>gamma (LIBM)</title>
  7. <meta name="description" content="gamma (LIBM)">
  8. <meta name="keywords" content="gamma (LIBM)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Math.html#Math" rel="up" title="Math">
  16. <link href="hypot.html#hypot" rel="next" title="hypot">
  17. <link href="frexp.html#frexp" rel="prev" title="frexp">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="gamma"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="hypot.html#hypot" accesskey="n" rel="next">hypot</a>, Previous: <a href="frexp.html#frexp" accesskey="p" rel="prev">frexp</a>, Up: <a href="Math.html#Math" accesskey="u" rel="up">Math</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="gamma_002c-gammaf_002c-lgamma_002c-lgammaf_002c-gamma_005fr_002c-gammaf_005fr_002c-lgamma_005fr_002c-lgammaf_005fr_002c-tgamma_002c-and-tgammaf_002d_002d_002dlogarithmic-and-plain-gamma-functions"></a>
  54. <h3 class="section">1.27 <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>&mdash;logarithmic and plain gamma functions</h3>
  55. <a name="index-gamma"></a>
  56. <a name="index-gammaf"></a>
  57. <a name="index-lgamma"></a>
  58. <a name="index-lgammaf"></a>
  59. <a name="index-gamma_005fr"></a>
  60. <a name="index-gammaf_005fr"></a>
  61. <a name="index-lgamma_005fr"></a>
  62. <a name="index-lgammaf_005fr"></a>
  63. <a name="index-tgamma"></a>
  64. <a name="index-tgammaf"></a>
  65. <p><strong>Synopsis</strong>
  66. </p><div class="example">
  67. <pre class="example">#include &lt;math.h&gt;
  68. double gamma(double <var>x</var>);
  69. float gammaf(float <var>x</var>);
  70. double lgamma(double <var>x</var>);
  71. float lgammaf(float <var>x</var>);
  72. double gamma_r(double <var>x</var>, int *<var>signgamp</var>);
  73. float gammaf_r(float <var>x</var>, int *<var>signgamp</var>);
  74. double lgamma_r(double <var>x</var>, int *<var>signgamp</var>);
  75. float lgammaf_r(float <var>x</var>, int *<var>signgamp</var>);
  76. double tgamma(double <var>x</var>);
  77. float tgammaf(float <var>x</var>);
  78. </pre></div>
  79. <p><strong>Description</strong><br>
  80. <code>gamma</code> calculates
  81. the natural logarithm of the gamma function of <var>x</var>. The gamma function
  82. (<code>exp(gamma(<var>x</var>))</code>) is a generalization of factorial, and retains
  83. the property that
  84. <code>exp(gamma(N))</code> is equivalent to <code>N*exp(gamma(N-1))</code>.
  85. Accordingly, the results of the gamma function itself grow very
  86. quickly. <code>gamma</code> is defined as
  87. the natural log of the gamma function, rather than the gamma function
  88. itself,
  89. to extend the useful range of results representable.
  90. </p>
  91. <p>The sign of the result is returned in the global variable <code>signgam</code>,
  92. which is declared in math.h.
  93. </p>
  94. <p><code>gammaf</code> performs the same calculation as <code>gamma</code>, but uses and
  95. returns <code>float</code> values.
  96. </p>
  97. <p><code>lgamma</code> and <code>lgammaf</code> are alternate names for <code>gamma</code> and
  98. <code>gammaf</code>. The use of <code>lgamma</code> instead of <code>gamma</code> is a reminder
  99. that these functions compute the log of the gamma function, rather
  100. than the gamma function itself.
  101. </p>
  102. <p>The functions <code>gamma_r</code>, <code>gammaf_r</code>, <code>lgamma_r</code>, and
  103. <code>lgammaf_r</code> are just like <code>gamma</code>, <code>gammaf</code>, <code>lgamma</code>, and
  104. <code>lgammaf</code>, respectively, but take an additional argument. This
  105. additional argument is a pointer to an integer. This additional
  106. argument is used to return the sign of the result, and the global
  107. variable <code>signgam</code> is not used. These functions may be used for
  108. reentrant calls (but they will still set the global variable <code>errno</code>
  109. if an error occurs).
  110. </p>
  111. <p><code>tgamma</code> and <code>tgammaf</code> are the &quot;true gamma&quot; functions, returning
  112. the gamma function of <var>x</var>&ndash;without a logarithm.
  113. (They are apparently so named because of the prior existence of the old,
  114. poorly-named <code>gamma</code> functions which returned the log of gamma up
  115. through BSD 4.2.)
  116. </p>
  117. <br>
  118. <p><strong>Returns</strong><br>
  119. Normally, the computed result is returned.
  120. </p>
  121. <p>When <var>x</var> is a nonpositive integer, <code>gamma</code> returns <code>HUGE_VAL</code>
  122. and <code>errno</code> is set to <code>EDOM</code>. If the result overflows, <code>gamma</code>
  123. returns <code>HUGE_VAL</code> and <code>errno</code> is set to <code>ERANGE</code>.
  124. </p>
  125. <br>
  126. <p><strong>Portability</strong><br>
  127. Neither <code>gamma</code> nor <code>gammaf</code> is ANSI C. It is better not to use either
  128. of these; use <code>lgamma</code> or <code>tgamma</code> instead.<br>
  129. <code>lgamma</code>, <code>lgammaf</code>, <code>tgamma</code>, and <code>tgammaf</code> are nominally C standard
  130. in terms of the base return values, although the <var>signgam</var> global for
  131. <code>lgamma</code> is not standard.
  132. </p>
  133. <br>
  134. <hr>
  135. <div class="header">
  136. <p>
  137. Next: <a href="hypot.html#hypot" accesskey="n" rel="next">hypot</a>, Previous: <a href="frexp.html#frexp" accesskey="p" rel="prev">frexp</a>, Up: <a href="Math.html#Math" accesskey="u" rel="up">Math</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  138. </div>
  139. </body>
  140. </html>