LGAMMA(3POSIX)

πŸ’– LGAMMA(3POSIX) β€” log gamma function πŸ’–

okay bestie, we're in the POSIX Programmer's Manual, and this page is about the log gamma function (plus its float and long double glow-ups). Pull up a chair, grab a boba, and let's get into it ✨


🌸 PROLOG 🌸

This manual page is part of the POSIX Programmer's Manual. Heads up though: the Linux implementation of this interface may differ (so go consult the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux at all. Not me being dramatic, that's just literally what it says 🫢


πŸ‘‘ NAME πŸ‘‘

lgamma, lgammaf, lgammal, signgam β€” log gamma function


✨ SYNOPSIS ✨

#include <math.h>

double lgamma(double x);
float lgammaf(float x);
long double lgammal(long double x);
extern int signgam;

πŸ’… DESCRIPTION πŸ’…

So the functionality described on this reference page is aligned with the ISO C standard. If anything here conflicts with the ISO C standard, that conflict is unintentional β€” no cap. This volume of POSIX.1‐2017 defers to the ISO C standard, periodt.

These functions shall compute:

log_e β”‚Ξ“(x)β”‚ where Ξ“(x) is defined as ∫e^ βˆ’tt^ xβˆ’1dt.

The argument x need not be a non-positive integer (Ξ“(x) is defined over the reals, except the non-positive integers). slay.

If x is NaN, -Inf, or a negative integer, the value of signgam is unspecified. so don't count on it, bestie 😭

These functions need not be thread-safe. iykyk.

An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred. that's your vibe check βœ…


πŸŽ€ RETURN VALUE πŸŽ€

Upon successful completion, these functions shall return the logarithmic gamma of x. main character behavior honestly.

  • If x is a non-positive integer, a pole error shall occur and lgamma(), lgammaf(), and lgammal() shall return +HUGE_VAL, +HUGE_VALF, and +HUGE_VALL, respectively. πŸ’€
  • If the correct value would cause overflow, a range error shall occur and lgamma(), lgammaf(), and lgammal() shall return Β±HUGE_VAL, Β±HUGE_VALF, and Β±HUGE_VALL (having the same sign as the correct value), respectively.
  • If x is NaN, a NaN shall be returned.
  • If x is 1 or 2, +0 shall be returned. cute.
  • If x is Β±Inf, +Inf shall be returned.

πŸ”₯ ERRORS πŸ”₯

These functions shall fail if:

Pole Error

The x argument is a negative integer or zero.

  • If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE].
  • If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the divide-by-zero floating-point exception shall be raised.

Range Error

The result overflows.

  • If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE].
  • If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow floating-point exception shall be raised.
The following sections are informative. (so like, the tea below is extra, not the law πŸ’–)

🌈 EXAMPLES 🌈

None. β€” yeah, nothing here, bestie. moving on πŸ¦‹


πŸ“ APPLICATION USAGE πŸ“

On error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other, but at least one of them must be non-zero. like, one of them has to show up to the party, okay? ✨


🧚 RATIONALE 🧚

None.


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ’œ SEE ALSO πŸ’œ

  • exp()
  • feclearexcept()
  • fetestexcept()
  • isnan()

Also, from The Base Definitions volume of POSIX.1‐2017: Section 4.20, Treatment of Error Conditions for Mathematical Functions, and <math.h>. go read those, bestie, they're iconic πŸ“š


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! πŸ’– this little love letter came to you from IEEE/The Open Group, 2017, and the manual page is literally called LGAMMA(3POSIX). go forth and compute your log gammas responsibly, mwah πŸŽ€βœ¨