Test macros: use defensive parentheses and std::fabs() for SG_CHECK_EQUAL_EP*

Some of the modules where I previously removed duplicate private
definitions of these macros had these features, and since they seem wise
to me, I'm applying them to the canonical SG_CHECK_EQUAL_EP() and
SG_CHECK_EQUAL_EP2() macros defined in simgear/misc/test_macros.hxx.
This commit is contained in:
Florent Rougon 2016-12-04 15:20:46 +01:00
parent e655d41817
commit 6b16f96c8a

View File

@ -2,7 +2,7 @@
#ifndef SG_MISC_TEST_MACROS_HXX
#define SG_MISC_TEST_MACROS_HXX
#include <cmath> // for fabs()
#include <cmath> // for std::fabs()
#define SG_CHECK_EQUAL(a, b) \
if ((a) != (b)) { \
@ -20,7 +20,7 @@
}
#define SG_CHECK_EQUAL_EP(a, b) \
if (fabs(a - b) > SG_EPSILON) { \
if (std::fabs((a) - (b)) > SG_EPSILON) { \
std::cerr << "failed with epsilon:" << #a << " != " << #b << std::endl; \
std::cerr << "\tgot:'" << a << "'" << std::endl; \
std::cerr << "\tat:" << __FILE__ << ":" << __LINE__ << std::endl; \
@ -28,7 +28,7 @@
}
#define SG_CHECK_EQUAL_EP2(a, b, ep) \
if (fabs(a - b) > ep) { \
if (std::fabs((a) - (b)) > ep) { \
std::cerr << "failed with epsilon:" << #a << " != " << #b << std::endl; \
std::cerr << "\tgot:'" << a << "'" << std::endl; \
std::cerr << "\tat:" << __FILE__ << ":" << __LINE__ << std::endl; \