[clutter] Use an epsilon for float comparison
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter] Use an epsilon for float comparison
- Date: Fri, 27 Apr 2012 11:32:45 +0000 (UTC)
commit 9c637ccb41adb33721b209bcc53732aba240d731
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Thu Apr 19 12:30:45 2012 +0100
Use an epsilon for float comparison
We tend to use float comparison for structured data types like Vertex,
Point, and Size; we should take into consideration fluctuations in the
floating point representation as well.
clutter/clutter-base-types.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/clutter/clutter-base-types.c b/clutter/clutter-base-types.c
index 90f3812..aefd164 100644
--- a/clutter/clutter-base-types.c
+++ b/clutter/clutter-base-types.c
@@ -39,6 +39,8 @@
#include <math.h>
+#define FLOAT_EPSILON (1e-15)
+
/*
@@ -277,9 +279,9 @@ clutter_vertex_equal (const ClutterVertex *vertex_a,
if (vertex_a == vertex_b)
return TRUE;
- return vertex_a->x == vertex_b->x &&
- vertex_a->y == vertex_b->y &&
- vertex_a->z == vertex_b->z;
+ return fabsf (vertex_a->x - vertex_b->x) < FLOAT_EPSILON &&
+ fabsf (vertex_a->y - vertex_b->y) < FLOAT_EPSILON &&
+ fabsf (vertex_a->z - vertex_b->z) < FLOAT_EPSILON;
}
static gboolean
@@ -469,7 +471,8 @@ clutter_point_equals (const ClutterPoint *a,
if (a == NULL || b == NULL)
return FALSE;
- return a->x == b->x && a->y == b->y;
+ return fabsf (a->x - b->x) < FLOAT_EPSILON &&
+ fabsf (a->y - b->y) < FLOAT_EPSILON;
}
/**
@@ -636,7 +639,8 @@ clutter_size_equals (const ClutterSize *a,
if (a == NULL || b == NULL)
return FALSE;
- return a->width == b->width && a->height == b->height;
+ return fabsf (a->width - b->width) < FLOAT_EPSILON &&
+ fabsf (a->height - b->height) < FLOAT_EPSILON;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]