summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-05-20 20:55:48 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-05-20 21:46:50 +0900
commitf40a452ee140b0cdc3734eb59b4beb51d2db88d2 (patch)
treeb258ac7ff77be6f5f76999b07b9e0854a1b2cd8a
parent5e95d7f2d83c1e107e44c60f1d6c27843ce280a7 (diff)
fix warnings about double/float comparisons in eina vector
this should fix T3245 this is basicall where we go double a == double b and due to precision issues this may not always be right, but this means that the equivalent now checks for "really close values" rather than perfectly exact. @fix
-rw-r--r--src/lib/eina/eina_inline_vector.x17
-rw-r--r--src/lib/eina/eina_types.h10
2 files changed, 22 insertions, 5 deletions
diff --git a/src/lib/eina/eina_inline_vector.x b/src/lib/eina/eina_inline_vector.x
index 040c0549ff..67f2e334fe 100644
--- a/src/lib/eina/eina_inline_vector.x
+++ b/src/lib/eina/eina_inline_vector.x
@@ -412,7 +412,9 @@ static inline Eina_Bool
412eina_vector3_equivalent(Eina_Vector3 *a, const Eina_Vector3 *b) 412eina_vector3_equivalent(Eina_Vector3 *a, const Eina_Vector3 *b)
413{ 413{
414 /* Assume "v" is a directional vector. (v->w == 0.0) */ 414 /* Assume "v" is a directional vector. (v->w == 0.0) */
415 return ((a->x == b->x) && (a->y == b->y) && (a->z == b->z)); 415 return (EINA_DOUBLE_EQUAL(a->x, b->x) &&
416 EINA_DOUBLE_EQUAL(a->y, b->y) &&
417 EINA_DOUBLE_EQUAL(a->z, b->z));
416} 418}
417 419
418static inline Eina_Bool 420static inline Eina_Bool
@@ -420,11 +422,16 @@ eina_vector3_triangle_equivalent(Eina_Vector3 *v0, Eina_Vector3 *v1,
420 Eina_Vector3 *v2, Eina_Vector3 *w0, 422 Eina_Vector3 *v2, Eina_Vector3 *w0,
421 Eina_Vector3 *w1, Eina_Vector3 *w2) 423 Eina_Vector3 *w1, Eina_Vector3 *w2)
422{ 424{
423 if (((v0->x == w0->x) && (v0->y == w0->y) && (v0->z == w0->z)) && 425 if ((EINA_DOUBLE_EQUAL(v0->x, w0->x) &&
424 ((v1->x == w1->x) && (v1->y == w1->y) && (v1->z == w1->z)) && 426 EINA_DOUBLE_EQUAL(v0->y, w0->y) &&
425 ((v2->x == w2->x) && (v2->y == w2->y) && (v2->z == w2->z))) 427 EINA_DOUBLE_EQUAL(v0->z, w0->z)) &&
428 (EINA_DOUBLE_EQUAL(v1->x, w1->x) &&
429 EINA_DOUBLE_EQUAL(v1->y, w1->y) &&
430 EINA_DOUBLE_EQUAL(v1->z, w1->z)) &&
431 (EINA_DOUBLE_EQUAL(v2->x, w2->x) &&
432 EINA_DOUBLE_EQUAL(v2->y, w2->y) &&
433 EINA_DOUBLE_EQUAL(v2->z, w2->z)))
426 return EINA_TRUE; 434 return EINA_TRUE;
427
428 return EINA_FALSE; 435 return EINA_FALSE;
429} 436}
430 437
diff --git a/src/lib/eina/eina_types.h b/src/lib/eina/eina_types.h
index 2e0c4d789f..b7bce493bd 100644
--- a/src/lib/eina/eina_types.h
+++ b/src/lib/eina/eina_types.h
@@ -410,6 +410,16 @@ typedef void (*Eina_Free_Cb)(void *data);
410#define EINA_C_ARRAY_LENGTH(arr) (sizeof(arr) / sizeof((arr)[0])) 410#define EINA_C_ARRAY_LENGTH(arr) (sizeof(arr) / sizeof((arr)[0]))
411 411
412/** 412/**
413 * @def EINA_DOUBLE_EQUAL
414 * Macro to compare 2 double floating point values and deal with precision
415 * loss issues.
416 *
417 * @since 1.18
418 */
419#define EINA_DOUBLE_EQUAL(x, y) \
420 (fabs((x) - (y)) <= (2.2204460492503131e-16) * fabs((x)))
421
422/**
413 * @} 423 * @}
414 */ 424 */
415 425