MCPcopy Create free account
hub / github.com/arguiot/TheoremJS / gamma

Method gamma

__test__/theorem.js:28–59  ·  view source on GitHub ↗
(z)

Source from the content-addressed store, hash-verified

26 return new BigNumber(n).times(this.factorial(new BigNumber(n).minus(1)))
27 }
28 gamma (z) {
29 const g = 7;
30 const p = [
31 0.99999999999980993,
32 676.5203681218851,
33 -1259.1392167224028,
34 771.32342877765313,
35 -176.61502916214059,
36 12.507343278686905,
37 -0.13857109526572012,
38 9.9843695780195716e-6,
39 1.5056327351493116e-7
40 ];
41 if (z < 0.5) {
42 return new BigNumber(Number(Math.PI / (Math.sin(Math.PI * z) * this.gamma(1 - z).toNumber())).toFixed(10));
43 }
44 else if(z > 100) return Math.exp(this.lngamma(z));
45 else {
46 z -= 1;
47 let x = p[0];
48 for (var i = 1; i < g + 2; i++) {
49 x += p[i] / (z + i);
50 }
51 const t = z + g + 0.5;
52
53 return new BigNumber(Number(Math.sqrt(2 * Math.PI)
54 * Math.pow(t, z + 0.5)
55 * Math.exp(-t)
56 * x
57 ).toFixed(10))
58 }
59 }
60 ln(x, n = 15) {
61 if (x.isComplex) {
62 return x.ln()

Callers 1

gamma.jsFile · 0.80

Calls 5

lngammaMethod · 0.95
sinMethod · 0.80
sqrtMethod · 0.80
expMethod · 0.45
powMethod · 0.45

Tested by

no test coverage detected