void check_one(double result, double expected, double reference, double reference_error, bool normalize = false) { if (normalize) { normalize_deg(result); normalize_deg(expected); normalize_deg(reference); } double res_max = (std::max)(bg::math::abs(result), bg::math::abs(expected)); if (res_max > 100 * std::numeric_limits<double>::epsilon()) { BOOST_CHECK_CLOSE(result, expected, 0.001); } else if (res_max > 10 * std::numeric_limits<double>::epsilon()) { BOOST_CHECK_CLOSE(result, expected, 0.1); } else if (res_max > std::numeric_limits<double>::epsilon()) { BOOST_CHECK_CLOSE(result, expected, 10); } // NOTE: in some cases it probably will be necessary to normalize // the differences between the result and expected result double ref_diff = bg::math::abs(result - reference); double ref_max = (std::max)(bg::math::abs(result), bg::math::abs(reference)); bool is_ref_close = ref_diff <= reference_error || ref_diff <= reference_error * ref_max; BOOST_CHECK_MESSAGE((is_ref_close), std::setprecision(16) << "{" << result << "} and {" << reference << "} not close enough."); }
void check_one(double result, double expected, double reference, double reference_error, bool normalize = false, bool check_reference_only = false) { if (normalize) { normalize_deg(result); normalize_deg(expected); normalize_deg(reference); } if (! check_reference_only) { double eps = std::numeric_limits<double>::epsilon(); double abs_result = bg::math::abs(result); double abs_expected = bg::math::abs(expected); double res_max = (std::max)(abs_result, abs_expected); double res_min = (std::min)(abs_result, abs_expected); if (res_min <= eps) // including 0 { bool is_close = abs_result <= 30 * eps && abs_expected <= 30 * eps; BOOST_CHECK_MESSAGE((is_close), std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}."); } else if (res_max > 100 * eps) { BOOST_CHECK_CLOSE(result, expected, 0.1); } else if (res_max > 10 * eps) { BOOST_CHECK_CLOSE(result, expected, 10); } else if (res_max > eps) { BOOST_CHECK_CLOSE(result, expected, 1000); } } // NOTE: in some cases it probably will be necessary to normalize // the differences between the result and expected result double ref_diff = bg::math::abs(result - reference); double ref_max = (std::max)(bg::math::abs(result), bg::math::abs(reference)); bool is_ref_close = ref_diff <= reference_error || ref_diff <= reference_error * ref_max; BOOST_CHECK_MESSAGE((is_ref_close), std::setprecision(20) << "result {" << result << "} and reference {" << reference << "} not close enough."); }
T difference_deg(T const& a1, T const& a2) { T d = a1 - a2; normalize_deg(d); return d; }