Recursive powering not working for big numbers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Recursive powering not working for big numbers

jamess
This post has NOT been accepted by the mailing list yet.
I have:

power :: Int -> Int -> Int
        power a b
           | b <= 0 = 0
           | b == 1 = a
           | otherwise = a * power a (b-1)

which works for 'power 2 10' and other small-ish results but not for 'power 3 561' - it just returns the wrong result. could anyone tell me why this might be?

Thanks a lot