请教floating point error: domain!奇怪!
#include "math.h" double ffts(a,b,eps,f)
double a,b,eps,(*f)();
{ int n,k;
double fa,fb,h,t1,p,s,x,t;
fa=(*f)(a); fb=(*f)(b);
n=1; h=b-a;
t1=h*(fa+fb)/2.0;
p=eps+1.0;
while (p>=eps)
{ s=0.0;
for (k=0;k<=n-1;k++)
{ x=a+(k+0.5)*h;
s=s+(*f)(x);
}
t=(t1+h*s)/2.0;
p=fabs(t1-t);
t1=t; n=n+n; h=h/2.0;
}
return(t);
}
#include "stdio.h"
#include "9ffts.c" (9ffts.c为上面函数文件名)
float e,z ;
main()
{ int i;
float a,eps,k,h;
float xx1,xx2,b;
float a12,b12,t12,h0,sum,fftsf(float);
scanf("%f,%f",&e,&k);
h0=315.0;
xx1=300.00;
xx2=-300.00;
for(i=0; ;i++)
{
z=e/(k*h0);
a=0.0; b=k*h0; eps=0.000001;
sum=ffts(a,b,eps,fftsf);
if((e<=0.0033)&&(e>0.0))
{if((sum>=xx2)&&(sum<=xx1))
{printf("z= %e\n,sum= %e\n k= %f\n",z,sum,k);
break;
}
if(sum<xx2)
k=k+0.0001;
if(sum>xx1)
k=k-0.0001;
}
else break;
}
return 0;
}
#include "math.h"
float fftsf(float x)
{
float y;
if((e<=0.002)&&(e>=0.0))
y=16.7*((2.0*(e-z*x))/0.002-((e-z*x)/0.002)*((e-z*x)/0.002));
else if((e<=0.0033)&&(e>=0.002))
y=16.7*((1.0-0.15*((e-z*x)-0.002)/0.0013));
else y=0;
return y;
}
当输入0.0001,0.5时,输出正确结果;
但当输入0.003,0.5时,显示floating point error: domain!在调试的时候发现循环语句是在循环,可是为什么最后就输不出结果呢?而显示floating point error: domain!