dimanche 20 mai 2018

less than comparison of two doubles not working properly

Look at this section of my code,

do{
    std::cerr<<"Intial Value of Output: "<<output<<std::endl;
    for(it=prob.begin();it!=prob.end();++it){
        if( output < ((it->second).second) ){
            input+=it->first;
            break;
        }   
    }
    std::cerr<<"Output lies in: "<<it->first<<" "<<(it->second).first<<" "<<(it->second).second<<std::endl;
    output-= ((it->second).first);
    output/=( ((it->second).second) - ((it->second).first) );
    std::cerr<<"Final Value of Output: "<<output<<std::endl;
    std::cin>>low;
}while(output!=0 && it!=prob.end());

The output of my program is as follows: Output of the program

It can be seen that the value of output is strictly less than the upper limit of range. Even then, 0.6 is coming in 0.4 - 0.6 range named as E (highlighted in the output image above).

Why is this Happening?

If anyone would like to try, this is the code and this is the input file.

Aucun commentaire:

Enregistrer un commentaire