When condition problem (probably newbie question).

Andreas Kostyrka <>
Fri Dec 18 19:20:15 CET 1998


Why does the following function not work as intended? It seems like the
test for N being even doesn't work :(

pow(N,0) -> io:write({pow,N,0}), io:nl(), 1;
pow(N,2) -> N * N;
pow(N,1) -> N;
pow(N,M) when N rem 2 == 0 ->
  io:write({powNeven,N,M}), io:nl(),
  X = pow(N,M div 2), X * X.

28> test:pow(10,3).
{powNeven,10,3}
100

Andreas
-- 
Win95: n., A huge annoying boot virus that causes random spontaneous system
     crashes, usually just before saving a massive project.  Easily cured by
     UNIX.  See also MS-DOS, IBM-DOS, DR-DOS, Win 3.x, Win98.




More information about the erlang-questions mailing list