[erlang-questions] Frying pan bug

Richard O'Keefe ok@REDACTED
Sat Mar 3 04:49:18 CET 2012


On 3/03/2012, at 12:42 AM, Joe Armstrong wrote:

> -module(bug).
> -compile(export_all).
> 
> bug() -> p(0.3, 4, 11).
> 
> c(N, M) ->  fac(M) div (fac(N)*fac(M-N)).
> 
> fac(0) -> 1;
> fac(N) -> N*fac(N-1).
> 
> p(P, M, N) -> 1.0 - math:pow(1-P, N-M)*c(N, M).

this calls fac(-7), which calls fac(-8), which
calls fac(-9), ...

Write

fac(N) when N >  1 -> N * fac(N-1);
fac(N) when N >= 0 -> 1.





More information about the erlang-questions mailing list