为什么浮点异常?

liv*_*495 0 c++

我有一个浮点异常,我不知道为什么.

代码是这样的:

void calcola_fitness(){
    vector<double> fitness;
    int n=nodes.size();
    int e=edges.size();
    int dim=feasibility.size();
    int feas=(feasibility[dim-1])*100;
    int narchi=numarchicoll[dim-1]/e;
    int numero_nodi=freePathNode.size()/n;
    double dist_start_goal=node_dist(0,1);
    int i,f,t;
    double pathlenght=0;
    int siize=freePathNode.size();
    for(i=0;i!=siize-1; i++){
        f=freePathNode[i].getIndex();
        i++;
        t=freePathNode[i].getIndex();
        i--;
        pathlenght=pathlenght+node_dist(f,t);
    }        
    double pathlenghtnorm=pathlenght/10*dist_start_goal;
    double fit=((double)numero_nodi+pathlenghtnorm+(double)narchi)*((double)feas);
    fitness.push_back(fit);
}
Run Code Online (Sandbox Code Playgroud)

有人能帮助我吗?有什么问题?我可以解决这个问题吗?非常感谢你

ken*_*ytm 5

"浮点异常"(SIGFPE)实际上是用词不当.任何种类的算术异常都会触发SIGFPE.这包括除零.

您应该检查是否nodesedges是空的.