gamma(3)

gamma3

Log gamma functions, gamma function

Part of lgamma(3).

Usage

#include <math.h>

extern int
signgam;

double

lgamma(double x);

double

lgamma_r(double x, int *signgamp);

float

lgammaf(float x);

float

lgammaf_r(float x, int *signgamp);

long double

lgammal(long double x);

long double

lgammal_r(long double x, int *signgamp);

double

gamma(double x);

double

gamma_r(double x, int *signgamp);

float

gammaf(float x);

float

gammaf_r(float x, int *signgamp);

long double

tgamma(double x);

float

tgammaf(float x);

long double

tgammal(long double x);

Library

Math Library (libm, -lm)

Overview

lgamma(x), lgammaf(x), and lgammal(x) return ln|Γ(x)|. The external integer signgam returns the sign of Γ(x).

lgamma_r(x, signgamp), lgammaf_r(x, signgamp), and lgammal_r(x, signgamp) provide the same functionality as lgamma(x), lgammaf(x), and lgammal(x), but the caller must provide an integer to store the sign of Γ(x).

The tgamma(x), tgammaf(x), and tgammal(x) functions return Γ(x), with no effect on signgam.

gamma(), gammaf(), gamma_r(), and gammaf_r() are deprecated aliases for lgamma(), lgammaf(), lgamma_r(), and lgammaf_r(), respectively.

Idiosyncrasies

Do not use the expression “signgam∗exp(lgamma(x))” to compute g := Γ(x). Instead use a program like this (in C):

lg = lgamma(x); g = signgam∗exp(lg);

Only after lgamma() or lgammaf() has returned can signgam be correct.

For arguments in its range, tgamma() is preferred, as for positive arguments it is accurate to within one unit in the last place. Exponentiation of lgamma() will lose up to 10 significant bits.

Return values

gamma(), gammaf(), gammal(), gamma_r(), gammaf_r(), gammal_r(), lgamma(), lgammaf(), lgammal(), lgamma_r(), lgammaf_r(), and lgammal_r() return appropriate values unless an argument is out of range. Overflow will occur for sufficiently large positive values, and non-positive integers. For large non-integer negative values, tgamma() will underflow.

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 49 times.

  1. 2.0.5
  2. 2.1.5–2.1.7.1
  3. 2.2.2–2.2.5
  4. 2.2.6–2.2.8
  5. 2.2.9
  6. 3.0–3.2
  7. 3.3–3.5.1
  8. 4.0–4.2
  9. 4.3
  10. 4.4
  11. 4.5–4.7
  12. 4.8–4.11
  13. 5.0
  14. 5.1–5.3
  15. 5.4–5.5
  16. 6.0–6.2
  17. 6.3
  18. 6.4
  19. 7.0
  20. 7.1
  21. 7.2
  22. 7.3
  23. 7.4
  24. 8.0
  25. 8.1
  26. 8.2
  27. 8.3
  28. 8.4
  29. 9.0
  30. 9.1
  31. 9.2
  32. 9.3
  33. 10.0
  34. 10.1
  35. 10.2
  36. 10.3
  37. 10.4
  38. 11.0
  39. 11.1
  40. 11.2
  41. 11.3
  42. 11.4
  43. 12.0
  44. 12.1
  45. 12.2
  46. 12.3
  47. 12.4
  48. 13.0–13.2
  49. 13.3–14.0
  50. 14.1–16.0

Standards

The lgamma(), lgammaf(), lgammal(), tgamma(), tgammaf(), and tgammal() functions are expected to conform to ISO/IEC 9899:1999 (“ISO C99”).

History

The lgamma() function appeared in 4.3BSD. The gamma() function appeared in 4.4BSD as a function which computed Γ(x). This version was used in FreeBSD 1.1. The name gamma() was originally dedicated to the lgamma() function, and that usage was restored by switching to Sun's fdlibm in FreeBSD 1.1.5. The tgamma() function appeared in FreeBSD 5.0. The 128-bit long double version of tgammal() replaced the 80-bit stub version in version in FreeBSD 14.1, thanks to an appropriate implementation from Arm.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.