How can I write a power function myself?

Posted by Koning WWWWWWWWWWWWWWWWWWWWWWW on Stack Overflow See other posts from Stack Overflow or by Koning WWWWWWWWWWWWWWWWWWWWWWW
Published on 2010-05-21T14:01:53Z Indexed on 2010/05/21 14:10 UTC
Read the original article Hit count: 260

Filed under:
|
|

Since I was 12, I was always wondering how I can make a function which calculates the power (e.g. 23) myself. In most languages these are included in the standard library, mostly as pow(double x, double y), but how can I write it myself?

I was thinking about for loops, but it think my brain got in a loop (when I wanted to do a power with a non-integer exponent, like 54.5 or negatives 2-21) and I went crazy ;)

So, how can I write a function which calculates the power of a real number? Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about math