Menu

Which gamma?

vasek
2008-02-23
2012-09-15
  • vasek

    vasek - 2008-02-23

    Hi,
    I am need to evaluate log(gamma(x)), and noticed that there are two implementations:
    bessel/gamma.cpp
    math/elem_math.cpp.

    In doc, it is recommended to use tgamma from elem_math. What is the rationale?
    In fact, lgamma is computed as log(exp(s)) where s is a function in tgamma.
    This looks numerically unstable to me.

    Isn't it more logical to define lgamma via "s" and tgamma as exp(lgamma)?

    Thanks,
    Vasek

     
    • vasek

      vasek - 2008-03-13

      Hi Adam,
      thanks for explanation.
      A historical rumor around our department is that I should avoid standard gamma from C but nobody is able to tell me the exact reason today. I will stick with the standard then.
      Vasek

       
    • Adam Piątyszek

      Adam Piątyszek - 2008-02-23

      Hi Vasek,

      I guess you should use lgamma() which is a part of <math.h> or <cmath>. On most platforms it uses an optimised way for calculation. The implementations of the lgamma() and tgamma() functions in IT++ are for portability purposes only for architectures, which miss them.

      As for the deprecation notice in elem_math.h, it only means that gamma() function name is misleading and will be changed to tgamma() in future major releases of IT++. This is because some platforms provide log(gamma(x)) under the gamma(x) name. That is why C99 standard uses tgamma() for the "true gamma" function.

      Hope this explanation helps.
      BR,
      /Adam

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.