(n)
| 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] |
nothing calls this directly
no test coverage detected
searching dependent graphs…