TGAMMA(3POSIX)

🌸 PROLOG 🌸

ok so first things first bestie β€” this page is part of the POSIX Programmer's Manual, and we're vibing with TGAMMA(3POSIX) today πŸ’…

Heads up tho: the Linux implementation of this interface may differ (so go peek at the matching Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux at all. πŸ™ˆ

✨ NAME ✨

tgamma, tgammaf, tgammal β€” compute gamma() function πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <math.h>

double tgamma(double x);
float tgammaf(float x);
long double tgammal(long double x);

πŸ’– DESCRIPTION πŸ’–

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 β€” this volume of POSIX.1‐2017 defers to the ISO C standard, periodt.

These functions shall compute Ξ“(x), where Ξ“(x) is defined as:

∫e^ βˆ’tt^ xβˆ’1dt

Now, if you're an application that wants to check for error situations (iconic behavior honestly), you should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. Then on return: if errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred. 😭


πŸ‘‘ RETURN VALUE πŸ‘‘

Upon successful completion, these functions shall return the gamma of x. slay.

  • If x is a negative integer, a domain error may occur, and either a NaN (if supported) or an implementation-defined value shall be returned. On systems that support the IEC 60559 Floating-Point option, a domain error shall occur and a NaN shall be returned. 😀
  • If x is Β±0, tgamma(), tgammaf(), and tgammal() shall return Β±HUGE_VAL, Β±HUGE_VALF, and Β±HUGE_VALL, respectively. On systems that support the IEC 60559 Floating-Point option, a pole error shall occur; otherwise, a pole error may occur.
  • If the correct value would cause overflow, a range error shall occur and tgamma(), tgammaf(), and tgammal() shall return Β±HUGE_VAL, Β±HUGE_VALF, or Β±HUGE_VALL, respectively, with the same sign as the correct value of the function.
  • If the correct value would cause underflow, and is not representable, a range error may occur, and tgamma(), tgammaf(), and tgammal() shall return 0.0, or (if IEC 60559 Floating-Point is not supported) an implementation-defined value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_MIN, respectively.
  • If the correct value would cause underflow, and is representable, a range error may occur and the correct value shall be returned. 🫢
  • If x is subnormal and 1/x is representable, 1/x should be returned.
  • If x is NaN, a NaN shall be returned.
  • If x is +Inf, x shall be returned.
  • If x is -Inf, a domain error shall occur, and a NaN shall be returned. πŸ’€

πŸ”₯ ERRORS πŸ”₯

These functions shall fail if:

  • Domain Error β€” the value of x is a negative integer, or x is -Inf.
    • If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [EDOM]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception shall be raised.
  • Pole Error β€” the value of x is 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 value 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.

These functions may fail if:

  • Domain Error β€” the value of x is a negative integer.
    • If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [EDOM]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception shall be raised.
  • Pole Error β€” the value of x is 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 underflows.
    • 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 underflow floating-point exception shall be raised.

The following sections are informative. πŸ‘€


πŸ“ EXAMPLES πŸ“

None.

not me giving you zero examples 😭 that's literally what it says tho


🧚 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. no cap.


πŸ’œ RATIONALE πŸ’œ

This function is named tgamma() specifically to avoid conflicts with the historical gamma() and lgamma() functions. iykyk β€” name collisions are the villain of every story. 😀


🌈 FUTURE DIRECTIONS 🌈

It is possible that the error response for a negative integer argument may be changed to a pole error and a return value of Β±Inf. so stay tuned bestie, plot twist pending πŸ‘‘


⭐ SEE ALSO ⭐

  • feclearexcept()
  • fetestexcept()
  • lgamma()

And from the Base Definitions volume of POSIX.1‐2017: Section 4.20, Treatment of Error Conditions for Mathematical Functions, and <math.h>. πŸ’…


ok legal bestie moment, gotta keep this exact because it's the law fr fr:

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 was IEEE/The Open Group, 2017 β€” TGAMMA(3POSIX) β€” signing off, mwah πŸ’‹