|Synopsis:||Floating point values shall not be compared using the == or != operators|
Due to rounding errors, most floating-point numbers end up being slightly imprecise. As long as this imprecision stays small, it can usually be ignored. However, it also means that numbers expected to be equal (e.g. when calculating the same result through different correct methods) often differ slightly, and a simple equality test fails. For example:
float a = 0.15 + 0.15 float b = 0.1 + 0.2 if (a == b) // can be false!
Solutions to this problem that are not correct include:
!(a < b) && !(a > b)
Please read [Dawson] to understand how to solve this issue.fabs(a - b) < Double.Epsilon