[erlang-questions] power(N,P), cant get it to work

Lev Walkin vlm@REDACTED
Tue Jun 17 10:11:01 CEST 2008


Circular Function wrote:
>   -module(math).
> -export([fac/1, sq/1,cube/1,power/2]).
> 
> fac(N) when N>0 ->
>         N * fac(N-1);
> fac(0) ->
>         1.
>    
> sq(X) -> X*X.
> 
> cube(X) -> X*X*X.
> 
> power(N,P) ->
>         if P==0 ->
>                 1;
>         true ->
>                 if P>0 ->
>                         N * power(N,P - 1);
>                 true ->
>                         1 / power(N,-1 * P).


place "end end." instead of "." on the last line.



More information about the erlang-questions mailing list