How should I do floating point comparison?
TL;DR Use the following function instead of the currently accepted solution to avoid some undesirable results in certain limit cases, while being potentially more efficient. Know the expected imprecision you have on your numbers and feed them accordingly in the comparison function. bool nearly_equal( float a, float b, float epsilon = 128 * FLT_EPSILON, float … Read more