summaryrefslogtreecommitdiff
path: root/glib/gmacros.h
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2017-02-08 17:34:23 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2018-05-29 09:55:47 +0100
commit24e98e38d616f64d68c86747dc38e657145bf38b (patch)
tree137198fb9e51906b8f17d6536ed5c679b84c844b /glib/gmacros.h
parent61ccf733ccf1f64760553f6915fc7264ca1af1d6 (diff)
downloadglib-24e98e38d616f64d68c86747dc38e657145bf38b.tar.gz
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
Diffstat (limited to 'glib/gmacros.h')
-rw-r--r--glib/gmacros.h3
1 files changed, 3 insertions, 0 deletions
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.