Wednesday 7 December 2016

c++ - floating point values comparison failure

In C, if we execute the following code:



float a = 0.7;
if (a < 0.7)
{
printf("Less");

}
else
{
printf("no");
}


The code above code prints "Less".



But if we execute the following code:




float a = 1.7;
if (a < 1.7)
{
printf("Less");
}
else
{
printf("no");
}



It prints "no".



What's the reason for that? How does the float datatype work?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...