/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <math.h>

double mylog(double x)
{
    int i;
    double res,q,f;
    if(x>1)
    {
        return 0.69314718055994530942+mylog(x/2);
    }
    else
    {
        f = x - 1;
        res = 0;
        q = -1;
        for(i=0;i<100;i++)
        {
            q *= -f;
            res += (q/(i+1));
        }
        return res;
   }
}
double mypow(double a, double x)
{
    int i;
    double res,q,d,f;
    if(x>1)
    {
        res = mypow(a,x/2);
        return res*res;
    }
    else
    {
        f = mylog(a);
        res = 1;
        q = 1;
        d = 1;
        for(i=1;i<100;i++)
        {
            q *= (f*x);
            d *= i;
            res += (q/d);
        }
    }
    return res;
}

int main()
{
    int i;
    printf("%f %f\n",pow(2,2),mypow(2,2));
    printf("%f %f\n",pow(2.5,2),mypow(2.5,2));
    printf("%f %f\n",pow(2,2.5),mypow(2,2.5));
    printf("%f %f\n",pow(2.5,2.5),mypow(2.5,2.5));
    return 0;
}
