title: Maclaurin series for ln(1+x)
body: <p>I'm trying to calculate in c++ the value of ln(1+x) using the Maclaurin series: x-x^2/2+x^3/3-...+(-1)^(n+1)*x^2n/2n. But if I insert a number larger than 2, the program will return the error nan.</p>
  
  <p>My code is here:</p>
  
  <pre><code>double ln(double x){
   double oldx=x,prec,t=x,i=1,eps=0.0001; 
  
  int semn=-1;
  
   do{ prec=x;
  
    t=t*oldx;
  
      i++;
      x=prec+(t/i)*semn;
      semn=-semn;
  
   }while(fabs(x-prec)&gt;=eps);
  
  return x;
  }
  </code></pre>
  
  <p>What can I do to get the right answer?</p>