This is critical section of the program that cause problem, and program is completely sequential.
exist_
is a class bool
private member, and dbl_num_
is a class double
private member
exist_ = false;
dbl_num_ = 0;
std::cout << dbl_num_ << " " ;
if(exist_ == true)
{
dbl_num_ = 5;
}else
{
dbl_num_ = NAN;
}
std::cout << exist_ << " " << dbl_num_ << std::endl;
With option -ffast-math, I got printout "0 0 5"
Without option -ffast-math, I got printout "0 0 NAN"
Furthermore if I change the program to
exist_ = false;
dbl_num_ = 0;
std::cout << dbl_num_ << " " ;
if(exist_ == true)
{
std::cout << exist_ << " " ;
dbl_num_ = 5;
}else
{
dbl_num_ = NAN;
}
std::cout << exist_ << " " << dbl_num_ << std::endl;
With option -ffast-math, I got "0 0 NAN"
Than I change the NAN to -5
exist_ = false;
dbl_num_ = 0;
std::cout << dbl_num_ << " " ;
if(exist_ == true)
{
dbl_num_ = 5;
}else
{
dbl_num_ = -5;
}
std::cout << exist_ << " " << dbl_num_ << std::endl;
With option -ffast-math, I got "0 0 -5"
I knew -ffast-math break IEEE standards, and it don't check NAN, but what is exactly the reason it break the above simple condition check?