| 140 | */ |
| 141 | |
| 142 | double 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 | } |
no test coverage detected