in reply to Calculate propabilities without recursion? Coin toss.
you need to either mix up the multiplications and divisions so the intermediate results stay near the magnitude of the final result, or operate in log-space:N! / (K! * (N-K)!) = (N * (N-1) * ... * (K+1)) / ((N-K) * (N-K-1) * ... * 1)
= exp((log N + log (N-1) + ... + log (K+1)) - (log (N-K) + log (N-K-1) + + ... + 0))
|
|---|