MCPcopy Create free account
hub / github.com/numpy/numpy / logfactorial

Function logfactorial

numpy/random/src/distributions/logfactorial.c:142–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140 */
141
142double logfactorial(int64_t k)
143{
144 const double halfln2pi = 0.9189385332046728;
145
146 if (k < (int64_t) (sizeof(logfact)/sizeof(logfact[0]))) {
147 /* Use the lookup table. */
148 return logfact[k];
149 }
150
151 /*
152 * Use the Stirling series, truncated at the 1/k**3 term.
153 * (In a Python implementation of this approximation, the result
154 * was within 2 ULP of the best 64 bit floating point value for
155 * k up to 10000000.)
156 */
157 return (k + 0.5)*log(k) - k + (halfln2pi + (1.0/k)*(1/12.0 - 1/(360.0*k*k)));
158}

Callers 1

hypergeometric_hruaFunction · 0.85

Calls 1

logFunction · 0.50

Tested by

no test coverage detected