MCPcopy
hub / github.com/josdejong/mathjs / lgammaComplex

Function lgammaComplex

src/function/probability/lgamma.js:69–92  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

67 })
68
69 function lgammaComplex (n) {
70 const TWOPI = 6.2831853071795864769252842 // 2*pi
71 const LOGPI = 1.1447298858494001741434262 // log(pi)
72
73 const REFLECTION = 0.1
74
75 if (n.isNaN()) {
76 return new Complex(NaN, NaN)
77 } else if (n.im === 0) {
78 return new Complex(lgammaNumber(n.re), 0)
79 } else if (n.re >= SMALL_RE || Math.abs(n.im) >= SMALL_IM) {
80 return lgammaStirling(n)
81 } else if (n.re <= REFLECTION) {
82 // Reflection formula. see Proposition 3.1 in [1]
83 const tmp = copysign(TWOPI, n.im) * Math.floor(0.5 * n.re + 0.25)
84 const a = n.mul(Math.PI).sin().log()
85 const b = lgammaComplex(new Complex(1 - n.re, -n.im))
86 return new Complex(LOGPI, tmp).sub(a).sub(b)
87 } else if (n.im >= 0) {
88 return lgammaRecurrence(n)
89 } else {
90 return lgammaRecurrence(n.conjugate()).conjugate()
91 }
92 }
93
94 function lgammaStirling (z) {
95 // formula ref in [2]

Callers

nothing calls this directly

Calls 9

lgammaNumberFunction · 0.90
copysignFunction · 0.90
lgammaStirlingFunction · 0.85
lgammaRecurrenceFunction · 0.85
isNaNMethod · 0.65
absMethod · 0.65
floorMethod · 0.65
logMethod · 0.65
sinMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…