这个程序咋会出现floating point error:domain的错误
谢谢大家啦#include"stdio.h"
#include"math.h"
#include"conio.h"
#include"graphics.h"
double x[32]={0.};
void fourl(int,int);
void realft(int,int);
main()
{int np=32,nn=16,i,j;
double df[32]={0.},y[32]={0.};
double f[32],fmin,fmax,ymin,ymax,l[32],h[32],PI=3.14159265359;
double ff,yy,lf,hy,lo=450.0,ho=250.0,dl=100.0,dh=50.0;
char s[10];
int graphdriver=DETECT,graphmode=1;
initgraph(&graphdriver,&graphmode,"");
for(i=0;i<=np-1;i++);
{ x[i]=sin(2*PI*i/16);
df[i]=x[i];
}
realft(1,nn);
printf("###########");
getch();
for(i=0;i<=np-1;i++) y[i]=x[i];
for(i=0;i<=np-1;i++) f[i]=i*32.0/32.0/60.0*1000.0;
fmin=f[0];fmax=f[0];ymin=y[0];ymax=y[0];
for(i=0;i<=np-1;i++)
{
if(fmin>f[i]) fmin=f[i];
if(fmax<f[i]) fmax=f[i];
if(ymin>y[i]) ymin=y[i];
if(ymax<y[i]) ymax=y[i];
};
for(i=0;i<=np-1;i++)
{
l[i]=(f[i]-fmin)/(fmax-fmin)*lo+dl;
h[i]=(ymax-y[i])/(ymax-ymin)*ho+dh;
}
rectangle(dl,dh,lo+dl,ho+dh);
for(i=0;i<=np-2;i++)
{line(l[i],h[i],l[i+1],h[i+1]);
}
for(i=0;i<=10;i++)
{
ff=(fmax-fmin)/10.0*i*100.0;
ff=(int)ff/100.0;
lf=lo/10.0*i+dl;
line(lf,ho+dh-3.0,lf,ho+dh+3.0);
sprintf(s,"%8.6f",ff);
outtextxy(lf-16.0,ho+dh+16.0,s);
}
for(j=0;j<=10;j++)
{yy=(ymax-(ymax-ymin)/10.0*j);
if(yy>0) yy=(int)yy/100.0+0.01;
if(yy<0) yy=(int)yy/100.0-0.01;
hy=ho/10.0*j+dh;
line(dl-3.0,hy,dl+3.0,hy);
sprintf(s,"%8.6f",yy);
outtextxy(dl-80.0,hy-5.0,s);
}
getch();
}
void realft(int sign,int nn)
{
double c1,c2,h1i,h1r,h2i,h2r,hir,wr,wi,wpr,wpi,wtemp,PI=3.14159265359,theta;
int i1,i2,i3,i4,j,n2p3;
c1=0.5;theta=PI/nn;
if(sign==1)
{
c2=-0.5;
fourl(1,nn);
printf("*************");
getch();
}
else
{
c2=0.5;
theta=-theta;
}
wpr=-2*pow(sin(theta/2),2);
wpi=sin(theta);
wr=1+wpr;
wi=wpi;
n2p3=2*nn+1;
for(j=1;j<=nn/2;j++)
{
i1=2*j;i2=i1+1;i3=n2p3-i2;i4=i3+1;
h1r=c1*(x[i1]+x[i3]);h1i=c1*(x[i2]-x[i4]);
h2r=-c2*(x[i2]+x[i4]);h2i=c2*(x[i1]-x[i3]);
x[i1]=h1r+wr*h2r-wi*h2i;x[i2]=h1i+wr*h2i+wi*h2r;
x[i3]=h1r-wr*h2r+wi*h2i;x[i4]=-h1i+wr*h2i+wi*h2r;
wtemp=wr;wr+=wr*wpr-wi*wpi;wi+=wi*wpr+wtemp*wpi;
}
if(sign==1)
{
hir=x[0];
x[0]=hir+x[1];
x[1]=hir-x[1];
}
else
{
hir=x[0];
x[0]=c1*(hir+x[1]);
x[1]=c1*(hir-x[1]);
fourl(-1,nn);
}
printf("$$$$$$$$");
getch();
return;
}
void fourl(int sign,int nn)
{
double wr,wi,wpr,wpi,wtemp,theta,tempr,tempi,PI=3.14159265359;
int i,j,m,mmax,istep,n=2*nn;
j=1;
for(i=1;i<=n;i+=2)
{
if(j>i)
{
tempr=x[j-1];
tempi=x[j];
x[j-1]=x[i-1];
x[j]=x[i];
x[i-1]=tempr;
x[i]=tempi;
}
m=n/2;
while(m>=2&&j>m)
{
j=j-m;m=m/2;
}
j+=m;
}
mmax=2;
while(n>mmax)
{
istep=2*mmax;theta=2*PI/(sign*mmax);
wpr=-2*pow(sin(theta/2),2);wpi=sin(theta);wr=1.0;wi=0.0;
for(m=1;m<=mmax;m+=2)
{
for(i=m;i<=n;i+=istep)
{
j=i+mmax;tempr=wr*x[j-1]-wi*x[j];tempi=wr*x[j]+wi*x[j-1];
x[j-1]=x[i-1]-tempr;x[j]=x[i]-tempi;x[i-1]+=tempr;x[i]+=tempi;
}
wtemp=wr;wr=wr*wpr-wi*wpi+wr;wi=wi*wpr+wtemp*wpi+wi;
}
mmax=istep;
}
printf("%%%%%%%%%%%");
getch();
}
----------------解决方案--------------------------------------------------------
bu 给点注释也不给题目 汗
.......... 我是看不下去
----------------解决方案--------------------------------------------------------