id summary reporter owner description type status priority milestone component version severity resolution keywords cc 6945 ARE_REAL_EQUAL is a mess Kurt Schwehr warmerdam "r39166 makes ARE_REAL_EQUAL even more hard to follow. This is a major maintenance hassle waiting to bite. {{{#!C++ // Test if 2 floating point values match. Useful when comparing values // stored as a string at some point. See #3573, #4183, #4506 #define ARE_REAL_EQUAL(dfVal1, dfVal2) \ /* Is it FLT_MIN ? Cf #6578 */ \ ((fabs(dfVal2) <= 3.4028234664e+38 && (float)dfVal2 == (float)1.17549435e-38 && fabs(dfVal1) <= 3.4028234664e+38) ? ((float)dfVal1 == (float)dfVal2) : \ /* Or DBL_MIN ? */ \ (dfVal2 == 2.2250738585072014e-308) ? (dfVal1 == dfVal2) : \ /* General case */ \ (dfVal1 == dfVal2 || fabs(dfVal1 - dfVal2) < 1e-10 || (dfVal2 != 0 && fabs(1 - dfVal1 / dfVal2) < 1e-10 ))) }}} Things that should be done with this: - An inline function - Use std::numeric_limits::foo() - Explain what is going on - Have C++ tests `~/src/gdal/autotest/cpp && find . -type f | xargs grep ARE_REAL_EQUAL` gives nothing - Is this for float or double or both? Why not have a template or separate functions? - what happens with +/- inf or NaNs? See also: - https://stackoverflow.com/questions/17333/what-is-the-most-effective-way-for-float-and-double-comparison - http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon " defect closed normal default unspecified major fixed