changed: measure relative error in a more standard way (knuth)

|(value-expected)/expected| < tol or |(value-expected)/value| < tol
instead of
|(value-expected)/(value+expected)|

this is how boost::test defines its check
This commit is contained in:
Arne Morten Kvarving 2020-10-27 09:55:43 +01:00
parent 778f486bcc
commit 6d1f8c75d6

View File

@ -59,8 +59,8 @@
#define CHECK_CLOSE(value, expected, reltol) \
{ \
if (std::fabs((expected) - (value)) > 1e-14 && \
std::fabs(((expected) - (value))/((expected) + (value))) > reltol) \
if (std::fabs((expected) - (value)) > reltol*std::fabs(expected) && \
std::fabs((expected) - (value)) > reltol*std::fabs(value)) \
throw std::runtime_error("Test failed: " + std::to_string(value) + " != " + std::to_string(expected)); \
}