Documentation Archive Developer
Search

ADC Home > Reference Library > Technical Q&As > Porting > Carbon >

The Gamma function in the Mac OS X 10.2 Math Library


Q: There are a number of functions described in /usr/include/math.h that deal with the gamma function. Which one should I use?

A: Going forward, the tgamma and lgamma functions provide the approximations required by the C99 standard. You should use them in new code. The function named gamma offers backward compatability to MacOS 9 and CarbonLib programs.

Historically, the MacOS 9 math libraries (and CarbonLib) have exported a routine named gamma() that approximates the Gamma function. The many variants of Unix (BSD, Posix, etc.) have offered routines named lgamma and gamma both approximating the log of the absolute value of the Gamma function, rather than the value of the Gamma function in its natural scale.

In Mac OS X there are three implementations of the Gamma function:

  1. The new tgamma function that approximates the Gamma function in its natural scale.

  2. The BSD lgamma function that approximates ln( | Gamma | ).

  3. The Mac OS 9 gamma function that approximates the Gamma function (depricated). This function preserves the MacOS9/CarbonLib gamma semantics, but its use is deprecated. New applications should call the modern tgamma function.


Note:
Unix applications that refer to the gamma function and expect to obtain the value ln( | Gamma | ) will need to be modified to reference the BSD lgamma function.




[Aug 27 2002]