Opened 7 years ago
Closed 7 years ago
#6945 closed defect (fixed)
ARE_REAL_EQUAL is a mess
Reported by: | Kurt Schwehr | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | default | Version: | unspecified |
Severity: | major | Keywords: | |
Cc: |
Description
r39166 makes ARE_REAL_EQUAL even more hard to follow. This is a major maintenance hassle waiting to bite.
// 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<typename>::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:
Note:
See TracTickets
for help on using tickets.
In 39324: