summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2011-07-12 01:02:43 +0100
committerRobert Bragg <robert@linux.intel.com>2011-07-14 13:54:05 +0100
commit32487af55b72e5a1be34176bc462ff11d8d378fc (patch)
tree478db94c2c19183a9b755378c97d6a1fab4f09c7
parentad234b303ca557c5f9bc34e0f4dfb0b3b619c865 (diff)
downloadclutter-32487af55b72e5a1be34176bc462ff11d8d378fc.tar.gz
Adds a CLUTTER_NEARBYINT macro for float rounding
This is a replacement for the nearbyint function which always rounds to the nearest integer. nearbyint is a C99 function so it might not always be available but also it seems in glibc it is defined as a function call so this macro could end up faster anyway. We can't just add 0.5 because it will break for negative numbers. Signed-off-by: Neil Roberts <neil@linux.intel.com> Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
-rw-r--r--clutter/clutter-private.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/clutter/clutter-private.h b/clutter/clutter-private.h
index 2c3dd6eb9..e9d0bd26b 100644
--- a/clutter/clutter-private.h
+++ b/clutter/clutter-private.h
@@ -84,6 +84,13 @@ typedef struct _ClutterMainContext ClutterMainContext;
#define P_(String) (String)
#endif
+/* This is a replacement for the nearbyint function which always rounds to the
+ * nearest integer. nearbyint is apparently a C99 function so it might not
+ * always be available but also it seems in glibc it is defined as a function
+ * call so this macro could end up faster anyway. We can't just add 0.5f
+ * because it will break for negative numbers. */
+#define CLUTTER_NEARBYINT(x) ((int) ((x) < 0.0f ? (x) - 0.5f : (x) + 0.5f))
+
typedef enum {
CLUTTER_ACTOR_UNUSED_FLAG = 0,