---
name: "tgamma"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/gamma"
---

# tgamma(3)

log gamma functions, gamma function

Part of [gamma(3)](/gamma/3.md).

## NAME

**lgamma**, **lgamma\_r**, **lgammaf**, **lgammaf\_r**, **lgammal**, **lgammal\_r**, **gamma**, **gamma\_r**, **gammaf**, **gammaf\_r**, **tgamma**, **tgammaf**, **tgammal**, – log gamma functions, gamma function

## LIBRARY

Math Library (libm, -lm)

## SYNOPSIS

**#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*);

## DESCRIPTION

**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.

## SEE ALSO

[math(3)](/math/3.md)

## 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.
