Never compare floats for equality

Floating point values cannot ever be compared for equality. GLib has a
G_APPROX_VALUE macro that lets us compare two value within a provided
precision, so we should use that instead.
This commit is contained in:
Emmanuele Bassi 2019-03-22 12:39:28 +00:00 committed by Benjamin Otte
parent f1cadee196
commit 40beb69487

View File

@ -735,7 +735,7 @@ gsk_rotate_transform_equal (GskTransform *first_transform,
GskRotateTransform *first = (GskRotateTransform *) first_transform;
GskRotateTransform *second = (GskRotateTransform *) second_transform;
return first->angle == second->angle;
return G_APPROX_VALUE (first->angle, second->angle, 0.01f);
}
static void
@ -837,8 +837,8 @@ gsk_rotate3d_transform_equal (GskTransform *first_transform,
GskRotate3dTransform *first = (GskRotate3dTransform *) first_transform;
GskRotate3dTransform *second = (GskRotate3dTransform *) second_transform;
return first->angle == second->angle
&& graphene_vec3_equal (&first->axis, &second->axis);
return G_APPROX_VALUE (first->angle, second->angle, 0.01f) &&
graphene_vec3_equal (&first->axis, &second->axis);
}
static void
@ -996,9 +996,9 @@ gsk_scale_transform_equal (GskTransform *first_transform,
GskScaleTransform *first = (GskScaleTransform *) first_transform;
GskScaleTransform *second = (GskScaleTransform *) second_transform;
return first->factor_x == second->factor_x
&& first->factor_y == second->factor_y
&& first->factor_z == second->factor_z;
return G_APPROX_VALUE (first->factor_x, second->factor_x, 0.01f) &&
G_APPROX_VALUE (first->factor_y, second->factor_y, 0.01f) &&
G_APPROX_VALUE (first->factor_z, second->factor_z, 0.01f);
}
static void
@ -1150,7 +1150,7 @@ gsk_perspective_transform_equal (GskTransform *first_transform,
GskPerspectiveTransform *first = (GskPerspectiveTransform *) first_transform;
GskPerspectiveTransform *second = (GskPerspectiveTransform *) second_transform;
return first->depth == second->depth;
return G_APPROX_VALUE (first->depth, second->depth, 0.001f);
}
static void