[erlang-questions] Frying pan bug
Fri Mar 2 12:56:12 CET 2012
On 03/02/2012 12:42 PM, Joe Armstrong wrote:
> 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).
> Running bug:bug() tries to turn my machine into a frying pan
> Should this be renamed frying_pan.erl ?
No,perhaps it should be renamed to "factorial_not_defined_properly.erl".
If you write the factorial function as follows:
fac(0) -> 1;
fac(N) when N > 0 -> N*fac(N-1).
you will be able to see what's happening.
More information about the erlang-questions