[求助]代码中“1e-15”是怎么来的?
一个简单的问题:(求圆周率) “1e-15”怎样体现那个限制条件? void main() {double a,b; double arctan(double x); a=16.0*arctan(1/5.0); //Arctan(x)=[(-1)nX2n+1]/(2n+1)
b=4.0*arctan(1/239.0); cout<<"PI="<<a-b<<"\n"; } double arctan(double x) {int i=1; double r=0,e=x,f,sqr=x*x; while(e/i>1e-15) //级数某项绝对值不大于10-15为止
{f=e/i; r=(i%4==1)?r+f:r-f; e*=sqr;i+=2;} return r; }