Ignacio's answer already mentions the use of logarithms. But in the end, we use exp() , which again is a library function. Therefore, if you do not want to use library functions at all, you need to resort to something like Taylor Extension x^y
Since a direct estimate of the Taylor expansion for x^y tedious, as Ignacio mentioned, base^power = exp( power*ln(base) ) . And the taylor extension for e ^ x is pretty simple and that for ln (x) is also very simple. Both of them give for a simple mutually recursive implementation in C
Here is a simple implementation of e^x using the above Taylor extension
double pow_x ( double x , unsigned i ) { double prod=1; if ( i == 0 ) return 1; while ( i ) { prod*=x; i--; } return prod; } long long factorial ( unsigned n ) { if ( n == 0 ) return 1; return n * factorial (n-1); } double expo ( double x, int terms ) { double sum=0; unsigned i=0; while ( i< terms ) { sum+= pow_x(x,i)/factorial(i); i++; } return sum; }
exp(5.93,20) gives 376.152869 , which Google generally agrees.
Hopefully using this example, you can implement ln(x) yourself.
source share