I'm assuming you mean after the program is compiled, how does it compare two floats. The way floats are stored is very unique. It is stored by sign, exponent and fraction as seen here. Therefore, unless it is absolutly equal, the program will see even 1 and 1.000000000001 as different. To check if they are almost equal, you can use the following:
bool AlmostEqualRelativeOrAbsolute(float A, float B,
float maxRelativeError, float maxAbsoluteError)
{
if (fabs(A - B) < maxAbsoluteError)
return true;
float relativeError;
if (fabs(B) > fabs(A))
relativeError = fabs((A - B) / B);
else
relativeError = fabs((A - B) / A);
if (relativeError <= maxRelativeError)
return true;
return false;
}
The code is obtained from here, you may want to read more at the site.
1.0 + 1.0 == 2.0
always holds;1.0/2.0 - 1.0/4.0 == 1.0/4.0
does too;1.0/3.0 + 1.0/3.0 == 2.0/3.0
does not. – Complaisance