I want to find value of In(x) without using math.h function
I am following this formula which I found in my math book:
log(m) base e = 2[ (m-1/m+1) + (1/3) * (m-1/m+1)^3 + (1/5) * (m-1/m+1)^5 + ... ]
Here is my code:
i = 3;
logx = 0 ;
ty = (x-1)/(x+1) ;
do
{
logx = logx + ty ;
tty = ty ;
ty = (ty * ((x-1)/(x+1)) * ((x-1)/(x+1))) / i ;
i = i + 2 ;
} while(tty - ty > 0.0000005 );
logx = 2*logx ;
printf("\n ln (%g) = %g \n", x, logx);
but this shows ln(2) = 0.691916
instead of 0.693147
and ln(3) = 1.08765
instead of 1.098612
etc. What is wrong?