From 24e98e38d616f64d68c86747dc38e657145bf38b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 8 Feb 2017 17:34:23 +0000 Subject: Add a macro for checking approximate values A macro like this is useful to avoid direct comparisons between floating point values. https://gitlab.gnome.org/GNOME/glib/issues/914 --- glib/gmacros.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'glib/gmacros.h') diff --git a/glib/gmacros.h b/glib/gmacros.h index 0e180bb09..cfeb9a00b 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -329,6 +329,9 @@ #undef CLAMP #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) +#define G_APPROX_VALUE(a, b, epsilon) \ + (((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon)) + /* Count the number of elements in an array. The array must be defined * as such; using this with a dynamically allocated array will give * incorrect results. -- cgit v1.2.1