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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
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