gamma(3)

✨ gamma β€” the (logarithm of the) gamma function, aka the flop era of math.h πŸ’…

okay bestie so the manual page is literally called gamma(3) and it lives in the Library Functions Manual, and we're about to unpack the messiest little trio in libm. gamma, gammaf, gammal β€” they're deprecated, they're confusing, and honestly? They're giving chaotic historical relic. But you asked, so let's go. 🫢


🌸 LIBRARY

Math library β€” that's libm, link it with -lm. Standard.


✨ SYNOPSIS

#include <math.h>

[[deprecated]] double gamma(double x);
[[deprecated]] float gammaf(float x);
[[deprecated]] long double gammal(long double x);
Notice the [[deprecated]] tags right there in the signature? Yeah. Your compiler is gonna side-eye you for using these. It's not subtle. πŸ’€

πŸŽ€ Feature Test Macro Requirements for glibc (see feature_test_macros(7))

gamma():

_XOPEN_SOURCE
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

gammaf(), gammal():

_XOPEN_SOURCE >= 600 || (_XOPEN_SOURCE && _ISOC99_SOURCE)
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

Like, yes you have to define the right macro or the declaration won't even show up. Vintage behavior, we don't make the rules. πŸ™ˆ


πŸ’– DESCRIPTION

So these functions are deprecated β€” instead, use either the tgamma(3) or the lgamma(3) functions, as appropriate. That's genuinely the whole plot. ✨

For the definition of the Gamma function, go look at tgamma(3). The math lore lives over there.

🌈 *BSD version

The libm in 4.4BSD and some versions of FreeBSD had a gamma() function that computes the Gamma function, as one would expect. Like, normal, sensible, correct behavior. Slay.

πŸ¦‹ glibc version

glibc has a gamma() function that is equivalent to lgamma(3) and computes the natural logarithm of the Gamma function. So if you were expecting the Gamma function itself... you're getting the log of it instead. Not the same thing at all, bestie. 😭 This is the whole reason this page is a certified mess.


πŸ‘‘ RETURN VALUE

See lgamma(3). That's it, that's the section. Go read the other one. ✨


πŸ“ ERRORS

See lgamma(3). Same deal, same vibe, same page. Go.


🧚 ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7).

  • gamma(), gammaf(), gammal() β€” Thread safety: MT-Unsafe race:signgam
⚠️ yeah, that's a race on signgam. Multithreaded + these functions = spicy. Be careful, please and thank you. πŸ’œ

⭐ STANDARDS

None. Not a single one. Nobody's claiming this. Periodt. πŸ’…


πŸ“œ HISTORY

SVID 2. Old old old.

Because of historical variations in behavior across systems, this function is not specified in any recent standard. Everyone did their own thing and honestly the standards people just walked away. 😭

So, lore time:

4.2BSD had a gamma() that computed ln(|Gamma(|x|)|), leaving the sign of Gamma(|x|) in the external integer signgam. Messy? A little. Iconic? Also yes.

In 4.3BSD the name was changed to lgamma(3), and the man page promises:

"At some time in the future the name gamma will be rehabilitated and
used for the Gamma function"

And this did indeed happen in 4.4BSD, where gamma() computes the Gamma function β€” with no effect on signgam. The prophecy was fulfilled! πŸŽ‰

...however, this came too late, and we now have tgamma(3), the "true gamma" function. The rehabilitated name never got its moment. Rip to the comeback tour that never happened. πŸ’€πŸŒΈ


🌈 SEE ALSO


and that's the whole page, bestie!! 🫢 it's from Linux man-pages 6.20, dated 2026-02-08, page gamma(3) β€” so like, very recent glow-up on a very ancient function, which is honestly the funniest possible energy. go use tgamma(3) or lgamma(3) instead, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms