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
This commit is contained in:
Carsten Haitzler 2016-05-20 20:55:48 +09:00
parent 5e95d7f2d8
commit f40a452ee1
2 changed files with 22 additions and 5 deletions

View File

@ -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;
}

View File

@ -409,6 +409,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)))
/**
* @}
*/