diff options
author | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2016-05-20 20:55:48 +0900 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2016-05-20 21:46:50 +0900 |
commit | f40a452ee140b0cdc3734eb59b4beb51d2db88d2 (patch) | |
tree | b258ac7ff77be6f5f76999b07b9e0854a1b2cd8a | |
parent | 5e95d7f2d83c1e107e44c60f1d6c27843ce280a7 (diff) | |
download | efl-f40a452ee140b0cdc3734eb59b4beb51d2db88d2.tar.gz |
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.x | 17 | ||||
-rw-r--r-- | src/lib/eina/eina_types.h | 10 |
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 eina_vector3_equivalent(Eina_Vector3 *a, const Eina_Vector3 *b) { /* Assume "v" is a directional vector. (v->w == 0.0) */ - return ((a->x == b->x) && (a->y == b->y) && (a->z == b->z)); + return (EINA_DOUBLE_EQUAL(a->x, b->x) && + EINA_DOUBLE_EQUAL(a->y, b->y) && + EINA_DOUBLE_EQUAL(a->z, b->z)); } static inline Eina_Bool @@ -420,11 +422,16 @@ eina_vector3_triangle_equivalent(Eina_Vector3 *v0, Eina_Vector3 *v1, Eina_Vector3 *v2, Eina_Vector3 *w0, Eina_Vector3 *w1, Eina_Vector3 *w2) { - if (((v0->x == w0->x) && (v0->y == w0->y) && (v0->z == w0->z)) && - ((v1->x == w1->x) && (v1->y == w1->y) && (v1->z == w1->z)) && - ((v2->x == w2->x) && (v2->y == w2->y) && (v2->z == w2->z))) + if ((EINA_DOUBLE_EQUAL(v0->x, w0->x) && + EINA_DOUBLE_EQUAL(v0->y, w0->y) && + EINA_DOUBLE_EQUAL(v0->z, w0->z)) && + (EINA_DOUBLE_EQUAL(v1->x, w1->x) && + EINA_DOUBLE_EQUAL(v1->y, w1->y) && + EINA_DOUBLE_EQUAL(v1->z, w1->z)) && + (EINA_DOUBLE_EQUAL(v2->x, w2->x) && + EINA_DOUBLE_EQUAL(v2->y, w2->y) && + EINA_DOUBLE_EQUAL(v2->z, w2->z))) return EINA_TRUE; - return EINA_FALSE; } 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); #define EINA_C_ARRAY_LENGTH(arr) (sizeof(arr) / sizeof((arr)[0])) /** + * @def EINA_DOUBLE_EQUAL + * Macro to compare 2 double floating point values and deal with precision + * loss issues. + * + * @since 1.18 + */ +#define EINA_DOUBLE_EQUAL(x, y) \ + (fabs((x) - (y)) <= (2.2204460492503131e-16) * fabs((x))) + +/** * @} */ |