mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-04 20:59:21 +02:00
Add fuzzy floating point comparison macro
Add a test macro that allows comparing two floating point values for equality within a certain tolerance. This macro has been independently reimplemented by various projects: * Clutter * Graphene * colord https://gitlab.gnome.org/GNOME/glib/issues/914
This commit is contained in:
@@ -69,6 +69,13 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
||||
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||
#n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'f'); \
|
||||
} G_STMT_END
|
||||
#define g_assert_cmpfloat_with_epsilon(n1,n2,epsilon) \
|
||||
G_STMT_START { \
|
||||
double __n1 = (n1), __n2 = (n2), __epsilon = (epsilon); \
|
||||
if (G_APPROX_VALUE (__n1, __n2, __epsilon)) ; else \
|
||||
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||
#n1 " == " #n2 " (+/- " #epsilon ")", __n1, "==", __n2, 'f'); \
|
||||
} G_STMT_END
|
||||
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
|
||||
gconstpointer __m1 = m1, __m2 = m2; \
|
||||
int __l1 = l1, __l2 = l2; \
|
||||
|
Reference in New Issue
Block a user