I’m trying to compare two coordinates. I found that my loop never stops because of this:
exit = ((p.x * sign_x) >= end_pos.x) && ((p.y * sign_y) >= end_pos.y);
cout<< p.x * sign_x << " >= " << end_pos.x
<< "=" << std::boolalpha << ((p.x * sign_x) >= end_pos.x)
<< " "
<< p.y * sign_y << " >= "<< end_pos.y
<< "=" << std::boolalpha << ((p.y * sign_y) >= end_pos.y)<<endl;
The exit variable never becomes true. In the console I see:
9435.6 >= 132.6=true 180 >= 180=false
How it can be?
All variables are float. Values are written above. Variables with 180 as value never change.
You haven’t provided example values of
p.yandsign_y, so it’s difficult to tell for sure.But the problem is almost certainly that
p.y * sign_yis not exactly equal to180; however it will be rounded when you print it.I suspect that if your print the value of
(p.y * sign_y) - end_pos.y, the result will not be0.