cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ] #include <mathcw.h> extern float gamicf (float a, float x); extern double gamic (double a, double x); extern long double gamicl (long double a, long double x); extern __float80 gamicw (__float80 a, __float80 x); extern __float128 gamicq (__float128 a, __float128 x); extern long_long_double gamicll (long_long_double a, long_long_double x); extern decimal_float gamicdf (decimal_float a, decimal_float x); extern decimal_double gamicd (decimal_double a, decimal_double x); extern decimal_long_double gamicdl (decimal_long_double a, decimal_long_double x); extern decimal_long_long_double gamicdll (decimal_long_long_double a, decimal_long_long_double x);
NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.
The ordinary and complementary incomplete gamma functions are defined by
where x is in [0, +Infinity], a is in [-Infinity, +Infinity]. They are related to the generalization of the factorial function, the complete gamma functiongamma(a,x) = integral(t = 0 to x) t**(a-1) exp(-t) dt, GAMMA(a,x) = integral(t = x to Infinity) t**(a-1) exp(-t) dt,
like this:GAMMA(a) = integral(t = 0 to Infinity) t**(a-1) exp(-t) dt,
gamma(a,x) + GAMMA(a,x) = GAMMA(a).
Mathematical notation conventionally uses a lowercase Greek letter for the ordinary incomplete function, and an uppercase Greek letter for both the complementary incomplete function, and the complete function. The number of arguments distinguishes between the two.
The C programming language family uses tgamma(a) (true gamma) for the complete function, and lgamma(a) for the logarithm of the absolute value of the complete function.
For arguments of large magnitude, and for a near zero, the gamma functions are subject to floating-point overflow and underflow, so it is conventional to work with scaled functions defined by
For a > 0, but not for zero or negative a, these functions are positive and satisfyg(a,x) = gamma(a,x) / GAMMA(a), G(a,x) = GAMMA(a,x) / GAMMA(a) (a > 0) G(a,x) = x**(-a) * exp(x) * GAMMA(a,x) / GAMMA(a) (a <= 0)
so both lie in [0,1].g(a,x) + G(a,x) = 1,
gami(a,x) computes g(a,x), gamic(a,x) computes G(a,x), and gamib(result,a,x) computes both the ordinary and complementary incomplete gamma functions, since the two are often needed together. Computationally, the single-result functions are just convenient wrappers around calls to gamib().
The case where both arguments are zero is indeterminate, and the stated values are what the code produces. In addition, since the complete gamma function is infinite at negative integer arguments, the ordinary incomplete gamma function and the scaled function g(a, x), are as well. However, G(a, x) is well-defined when its first argument is a negative integer.G(a, 0) = 1 g(a, 0) = 0 if a > 0, G(a, 0) = Infinity g(a, 0) = 1 if a = 0, G(a, 0) = 1/a g(a, 0) = Infinity if a < 0,