lnCombination

Computes the natural logarithm of the binomial coefficient "n choose k".

The logarithmic form avoids overflow for large n and k. Computed as lnFactorial(n) - lnFactorial(k) - lnFactorial(n - k). Returns 0.0 when k is 0 or equal to n (since C(n, 0) = C(n, n) = 1).

Example:

lnCombination(10, 3) // 4.7874... (ln(120), since C(10,3) = 120)
lnCombination(5, 0) // 0.0 (ln(1))

Return

the natural logarithm of C(n, k).

Parameters

n

the total number of items. Must be non-negative.

k

the number of items to choose. Must satisfy 0 <= k <= n.