我的C程序的浮点异常

时间:2012-10-04 20:37:17

标签: c exception point floating

这是导致问题的部分。我真的找不到任何不好的东西。该部分用于前端结构的mel binning功能。

原始文件位于http://www.ee.columbia.edu/~stanchen/fall12/e6870/labs/lab1.html

提前感谢您的帮助!

double fmax = 0;
double w = 0;       // half of the length of the bottom line of each bin of triangular

fmax = 1127*log(1+1/(1400*samplePeriod));
w = fmax/27;

double f    = 0;
double fmel = 0;
double xf   = 0;
double H    = 0;
double sum  = 0;

for (int frmIdx = 0; frmIdx < inFrameCnt; ++frmIdx)
    for (int dimIdx = 0; dimIdx < outDimCnt; ++dimIdx){
        sum = 0;
        for (int j = 0; j < 256; ++j){
            f = j/(256/20000);
            fmel = 1127*log(1+f/700);
            xf = sqrt(inFeats(frmIdx,2*j)*inFeats(frmIdx,2*j)+inFeats(frmIdx,2*j+1)*inFeats(frmIdx,2*j+1));
            if (fmel > dimIdx*w && fmel < (dimIdx+1)*w){
                H = (fmel- dimIdx*w)/w;
            }
            else if(fmel > ((dimIdx+1)*w) && fmel < ((dimIdx+2)*w)){
                H = ( (dimIdx+2)*w-fmel)/w;
            }
            else {
                H = 0;
            }
            sum = sum + xf*H;
        }
        outFeats(frmIdx,dimIdx)=sum;

        if (doLog == true){
            outFeats(frmIdx,dimIdx) = log(outFeats(frmIdx,dimIdx));
        }
        else{
            outFeats(frmIdx,dimIdx) = outFeats(frmIdx,dimIdx);
        }
    }

1 个答案:

答案 0 :(得分:1)

检查零没有分割。
这是第一个按定义为0的人:
f = j /(256/20000); //(256和20000被视为整数)
256. / 20000.(或256.0 / 20000.0)会浮动。