MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.34k stars 480 forks source link

gamma implementation... #24

Closed Hypercubed closed 8 years ago

Hypercubed commented 8 years ago

Would you consider a PR for a gamma function implementation? I have a Decimal.js gamma function implemented using the Lanczos approximation.

MikeMcl commented 8 years ago

That would probably be too specialised to be included, but you are welcome to post it here. Perhaps mathjs would be interested, as it uses this library under the hood.

josdejong commented 8 years ago

math.js has an implementation of the gamma function. The number implementation uses the Lanczos approximation for small values, and an extended Stirling approximation for large values. The BigNumber (decimal.js) implementation only supports integers and still has to be extended with support for non-integer input, so @Hypercubed you could contribute there.

Here is the concerning sourcecode: https://github.com/josdejong/mathjs/blob/master/lib/function/probability/gamma.js

Hypercubed commented 8 years ago

Hi @josdejong , actually my implementation of the Lanczos approximation in decimal.js was created by looking closely at the math.js complex gamma function (as well as wikipedia and https://github.com/substack/gamma.js). I was attempting to make a Big-Complex gamma function, and that, in turn, required a decimal.js gamma function.

However, this morning I realized that the result is not precise. The approximation is limited to the precision of the coefficients. Implementing arbitrary precision Chebyshev polynomials looks painful.

josdejong commented 8 years ago

ah ok. Well, thanks anyway. Maybe some day if you feel like it ;)

Hypercubed commented 8 years ago

I'll keep working on it. From what I have seen in various resources online it's not an easy problem. I have some hopes for this: http://www.ebyte.it/library/downloads/2007_MTH_Nemes_GammaFunction.pdf

If I come up with anything I'll do a PR at math.js.