mathnet-numerics icon indicating copy to clipboard operation
mathnet-numerics copied to clipboard

Gamma function

Open verybadcat opened this issue 11 years ago • 1 comments

I've found a C# version of code that appears to be used by e.g. Apple to compute the Gamma function, together with evidence that it's been around the web since the 1980s. It needed some adaptation as the code appeared to be optimized for a smaller floating-point type than the 64 bits one typically sees today. My adapted version produces exact answers at integers, which was a motivation for the change, and is within a factor of 10^-12 of the existing implementation elsewhere.

See the discussion here for background:

https://github.com/mathnet/mathnet-numerics/issues/196

verybadcat avatar Mar 25 '14 18:03 verybadcat

This fixes your issues about accuracy and also about GammaLn with negative inputs. I'm choosing to return NaN for GammaLn in cases where the Gamma function is negative. But it is arguable whether this is the right choice; one could return the real part of the log instead.

verybadcat avatar Apr 16 '15 09:04 verybadcat