I'm trying to compute ln(x) by Taylor series. Here is my code:
#define N 10 float ln(float x){ int i; float result; float xt; float xtpow; int sign; if(x > 0 && x <= 1){ xt = x - 1.0; sign = -1; xtpow = 1.0; result = 0; for(i = 1 ; i < N + 1; i++ ); { // Problem here printf("%d\n", i); sign = sign * (-1); xtpow *= xt; result += xtpow * sign / i; } }else if(x >= 1) { return -1 * ln(1.0 / x); } return result; }
The problem is with my series cycle(see above). It seems like after 1 cycle variable i
becomes equal N + 1
, and nothing going on after it. Have you any ideas why it is so?