当前位置: 代码迷 >> C语言 >> 求助,为什么浮点运算老是超过上限?
  详细解决方案

求助,为什么浮点运算老是超过上限?

热度:548   发布时间:2008-02-02 10:57:31.0
求助,为什么浮点运算老是超过上限?
麻烦大家帮我看看以下的程序,为什么运行后提示浮点运算超过上限?

#include "stdio.h"
#include "math.h"
main()
{
float Pleft,Pright,Wide,Distance;
int NumDivide,i,j,k;
float PHI,DeltaPhi;
int StepNum;
float ConN,SteelN,TySN,N1,N2,N3;  
float ConDis[600],ConArea[600],ConYL[600],ConYB[600],ConNDim[600];
float GangBanLeft,GangBanRight,GangBanWide,GangBanDistance;
int GangBanDivide;
float GangBanDis[600],GangBanArea[600],GangBanYL[600],GangBanYB[600],GangBanNDim[600];
int SteelNum;
float SteelDis[4]={-125,-45,45,125},SteelArea[4]={452,226,226,452};
float SteelYL[4],SteelYB[4],SteelNDim[4];
int TySNum;
float TySDis[2]={-94.5,94.5},TySArea[2]={1100,1100};
float TySYL[2],TySYB[2],TySNDim[2];
float fc,Ec,sigma0,sigmau;
float fy,Es,fa,Ea;
float YaLi,sigma_ave,sigma1,sigma2,sigma3;
float qfqlGJ,qfqlGB,jxql,Maxql,MaxM;
int flagGJ,flagGB,flagCon;
float MCon,MSteel,MTyS,MGangBan;

Pleft=-150;Pright=150;Wide=300;Distance=Pright;
NumDivide=600;

GangBanDivide=300;
GangBanLeft=-89;GangBanRight=89;GangBanWide=7;
GangBanDistance=GangBanRight;

for(i=0;i<NumDivide;i++)
{  
    Distance=Distance-(Pright-Pleft)/NumDivide;
    ConDis[i]=Distance+(Pright-Pleft)/(2*NumDivide);
    ConArea[i]=Wide*(Pright-Pleft)/NumDivide;
}

for(i=0;i<GangBanDivide;i++)
{  
    GangBanDistance=GangBanDistance-(GangBanRight-GangBanLeft)/GangBanDivide;
    GangBanDis[i]=GangBanDistance+(GangBanRight-GangBanLeft)/(2*GangBanDivide);
    GangBanArea[i]=GangBanWide*(GangBanRight-GangBanLeft)/GangBanDivide;
}

printf("\n The     ConDis         ConArea\n");
for(i=0;i<NumDivide;i++)
{printf("ConDis[%d]=%f ConArea[%d]=%f",i,ConDis[i],i,ConArea[i]);}
printf("\n The     GangBanDis         GangBanArea\n");
for(i=0;i<GangBanDivide;i++)
{printf("GangBanDis[%d]=%f GangBanArea[%d]=%f",i,GangBanDis[i],i,GangBanArea[i]);}


SteelNum=4;



TySNum=2;

fc=34.3;sigma0=0.002;

fy=340;Es=2.0e5;fa=273;Ea=2.1e5;

PHI=0;
printf("input:DeltaPhi=?\n");
scanf("%f",&DeltaPhi);
printf("input:sigma_ave=?\n");
scanf("%f",&sigma_ave);
printf("input:YaLi=?\n");
scanf("%f",&YaLi);
printf("input:StepNum=?\n");
scanf("%d",&StepNum);
PHI=0;
for(k=0;k<StepNum;k++)
{
    PHI=PHI+k*DeltaPhi;
    sigma1=sigma_ave;
    N1=TF(ConDis[600],ConArea[600],GangBanDis[600],GangBanArea[600],SteelDis[4],SteelArea[4],TySDis[2],TySArea[2],PHI,sigma1);
    if(abs(1-N1/YaLi<0.001))
    {
        sigma_ave=sigma1;
        goto CCC;
    }
    else
    AAA:  if(N1<YaLi)
    {
        sigma2=sigma1+1e-7;
    }
         else
    {
        sigma2=sigma1-1e-7;
    }
    N2=TF(ConDis[600],ConArea[600],GangBanDis[600],GangBanArea[600],SteelDis[4],SteelArea[4],TySDis[2],TySArea[2],PHI,sigma2);
    if(abs(1-N2/YaLi<0.001))
    {
        sigma_ave=sigma2;
        goto CCC;
    }
    else
       if((N1-YaLi)*(N2-YaLi)>0)
       {
           sigma1=sigma2;
           N1=N2;
           goto AAA;
       }
       else
   BBB:  {
           sigma3=sigma1+0.618*(sigma1-sigma2);
           N3=TF(ConDis[600],ConArea[600],GangBanDis[600],GangBanArea[600],SteelDis[4],SteelArea[4],TySDis[2],TySArea[2],PHI,sigma3);
           if(abs(1-N3/YaLi<0.001))
           {
               sigma_ave=sigma3;
               goto CCC;
           }
           else
             if((N1-YaLi)*(N3-YaLi)<0)
             {
                 sigma2=sigma3;
                 N2=N3;
                 goto BBB;
             }
             else
             {
                 sigma1=sigma3;
                 N1=N3;
                 goto BBB;
             }
   }
CCC:for(i=0;i<NumDivide;i++)
   {
       ConYB[i]=sigma_ave-PHI*ConDis[i];
       if(ConYB[i]<0)
       {
          ConYL[i]=0;
       }
       if(ConYB[i]>=0)
       {
          ConYL[i]=fc*(1.7*ConYB[i]/sigma0-0.4*ConYB[i]*ConYB[i]/(sigma0*sigma0)-0.3*ConYB[i]*ConYB[i]*ConYB[i]/(sigma0*sigma0*sigma0));
       }
       if(ConYB[i]>sigma0)
       {
          ConYL[i]=fc*ConYB[i]*sigma0/(2*(ConYB[i]-sigma0)*(ConYB[i]-sigma0)+ConYB[i]*sigma0);
       }
   }
   
   for(i=0;i<GangBanDivide;i++)
   {
       GangBanYB[i]=sigma_ave-PHI*GangBanDis[i];
    GangBanYL[i]=GangBanYB[i]*Ea;
       if(GangBanYL[i]>fa)
       {
          GangBanYL[i]=fa;
       }
       if(GangBanYL[i]<-fa)
       {
          GangBanYL[i]=-fa;
       }
   }
   
      for(i=0;i<SteelNum;i++)
   {
       SteelYB[i]=sigma_ave-PHI*SteelDis[i];
    SteelYL[i]=SteelYB[i]*Es;
       if(SteelYL[i]>fy)
       {
          SteelYL[i]=fy;
       }
       if(SteelYL[i]<-fy)
       {
          SteelYL[i]=-fy;
       }
   }
   
    for(i=0;i<TySNum;i++)
   {
       TySYB[i]=sigma_ave-PHI*TySDis[i];
    TySYL[i]=TySYB[i]*Ea;
       if(TySYL[i]>fa)
       {
          TySYL[i]=fa;
       }
       if(TySYL[i]<-fa)
       {
          TySYL[i]=-fa;
       }
   }
   
   
   flagCon=0;flagGJ=0;flagGB=0;
   for(i=0;i<NumDivide;i++)
   {
       if((flagCon==0)&&(ConYB[i]>=sigma0))
       {
           flagCon=1;
           jxql=PHI;
       
   }
   
   for(i=0;i<SteelNum;i++)
   {
       if((flagGJ==0)&&(SteelYL[i]>=-fy))
       {
           
           flagGJ=1;
           qfqlGJ=PHI;
       }
   }
   
   for(i=0;i<TySNum;i++)
   {
       if((flagGB==0)&&(TySYL[i]>=-fa))
       {
           
           flagGB=1;
           qfqlGB=PHI;
       }
   }    


MCon=0;MSteel=0;MTyS=0;MGangBan=0;MaxM=0;      

  for(i=0;i<NumDivide;i++)    
  {
      MCon=MCon+ConArea[i]*ConYL[i]*ConDis[i];
  }
  
  for(i=0;i<SteelNum;i++)    
  {
      MSteel=MSteel+SteelArea[i]*SteelYL[i]*SteelDis[i];
  }
  
  for(i=0;i<TySNum;i++)    
  {
      MTyS=MTyS+TySArea[i]*TySYL[i]*TySDis[i];
  }
  
  for(i=0;i<GangBanDivide;i++)    
  {
      MGangBan=MGangBan+GangBanArea[i]*GangBanYL[i]*GangBanDis[i];
  }
  
  if(abs(MCon+MSteel+MTyS+MGangBan)>MaxM)
  {
      Maxql=PHI;
  }
  MaxM=abs(MCon+MSteel+MTyS+MGangBan);
  
  printf("This is %d\n",k);
  printf("PHI=%f\n",PHI);
  printf("M=%f\n",(MCon+MSteel+MTyS+MGangBan)/1000000);
}
  
  printf("qfql-------Steel=%f\n",qfqlGJ);
  printf("qfql-------GangBan=%f\n",qfqlGB);
  printf("jxql-------Con=%f\n",jxql);
  printf("jxql-------=%f\n",Maxql);
}
}
TF(float CD[600],float CA[600],float GD[600],float GA[600],float SD[4],float SA[4],float TD[2],float TA[2],float PH,float sig)
{   float CYB[600],CYL[600],GYB[600],GYL[600],SYB[4],SYL[4],TYB[2],TYL[2];
    float CND[600],CN,GND[600],GN,SND[4],SN,TND[2],TN,N;
    float fC,EC,S0,SU;
    float fY,ES,fA,EA;
    int j,NDivide,GDivide,SNum,TNum;
    
    fC=34.3;S0=0.002;
    fY=340;ES=2.0e5;fA=273;EA=2.1e5;
    NDivide=600;GDivide=300;SNum=4;TNum=2;
    CN=0;GN=0;SN=0;TN=0;
    
    for(j=0;j<NDivide;j++)
   {
       CYB[j]=sig-PH*CD[j];
       if(CYB[j]<0)
       {
          CYL[j]=0;
       }
       if(CYB[j]>=0)
       {
          CYL[j]=fC*(1.7*CYB[j]/S0-0.4*CYB[j]*CYB[j]/(S0*S0)-0.3*CYB[j]*CYB[j]*CYB[j]/(S0*S0*S0));
       }
       if(CYB[j]>S0)
       {
          CYL[j]=fC*CYB[j]*S0/(2*(CYB[j]-S0)*(CYB[j]-S0)+CYB[j]*S0);
       }
       CND[j]=CYL[j]*CA[j];
       CN=CN+CND[j];
   }
   
   for(j=0;j<GDivide;j++)
   {
       GYB[j]=sig-PH*GD[j];
    GYL[j]=GYB[j]*EA;
       if(GYL[j]>fA)
       {
          GYL[j]=fA;
       }
       if(GYL[j]<-fA)
       {
          GYL[j]=-fA;
       }
       GND[j]=GYL[j]*GA[j];
       GN=GN+GND[j];
   }
   
   for(j=0;j<SNum;j++)
   {
       SYB[j]=sig-PH*SD[j];
    SYL[j]=SYB[j]*ES;
       if(SYL[j]>fY)
       {
          SYL[j]=fY;
       }
       if(SYL[j]<-fY)
       {
          SYL[j]=-fY;
       }
       SND[j]=SYL[j]*SA[j];
       SN=SN+SND[j];
   }
   
    for(j=0;j<TNum;j++)
   {
       TYB[j]=sig-PH*TD[j];
    TYL[j]=TYB[j]*EA;
       if(TYL[j]>fA)
       {
          TYL[j]=fA;
       }
       if(TYL[j]<-fA)
       {
          TYL[j]=-fA;
       }
       TND[j]=TYL[j]*TA[j];
       TN=TN+TND[j];
   }
   N=CN+GN+SN+TN;
   return(N);
}
搜索更多相关的解决方案: float  浮点运算  上限  int  

----------------解决方案--------------------------------------------------------
晕掉了
你一点注释也没有
谁会有耐心帮你看呢?
----------------解决方案--------------------------------------------------------
疯掉了.....
你这个程序是干嘛的呀?
那么多变量,谁看了都要疯掉了
----------------解决方案--------------------------------------------------------
回复 1# 的帖子
哇,无语了!
----------------解决方案--------------------------------------------------------
失败的代码
----------------解决方案--------------------------------------------------------
吆 西.
----------------解决方案--------------------------------------------------------
无语
[bc07]
----------------解决方案--------------------------------------------------------
好长啊...现在上班...晚上回去帮你看看

PS:不注释不是好习惯

[[it] 本帖最后由 peach5460 于 2008-2-29 08:42 编辑 [/it]]
----------------解决方案--------------------------------------------------------
SuperBoy
----------------解决方案--------------------------------------------------------
  相关解决方案