I assume that you mean when a program is compiled, how it compares two floats. The float storage method is very unique. It is stored by sign, exponent and fraction, as shown here . Therefore, if it is not absolutely equal, the program will see even 1 and 1.000000000001 as different. To make sure 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 can find out more on the site.
Ivan Ling
source share