tests: Accept slightly different numeric results
authorSimon McVittie <smcv@debian.org>
Tue, 22 Aug 2023 09:49:36 +0000 (10:49 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 24 Aug 2023 14:27:18 +0000 (10:27 -0400)
FLT_EPSILON is the distance between 1.0 and the next distinct floating
point number, and doesn't necessarily have anything to do with the
precision we can expect from a series of floating-point calculations.
Experimentally, 1e-6 is achievable, even on platforms with unusual
floating point implementations like i387.

Resolves: https://gitlab.gnome.org/GNOME/gtk/-/issues/6051
Bug-Debian: https://bugs.debian.org/1050076
Signed-off-by: Simon McVittie <smcv@debian.org>
testsuite/gtk/colorutils.c

index b4d42e2bb228d9350025f1379d35165dce18b4fa..8f0acfb5e6c0192e6c9fdd92565fdf1d4e4f9570 100644 (file)
@@ -30,6 +30,10 @@ struct {
   { 1, 0, 1, 5.0 / 6.0, 1, 1 },
 };
 
+/* Close enough for float precision to match, even with some
+ * rounding errors */
+#define EPSILON 1e-6
+
 static void
 test_roundtrips (void)
 {
@@ -40,13 +44,13 @@ test_roundtrips (void)
 
       g_print ("color %u\n", i);
       gtk_hsv_to_rgb (tests[i].h, tests[i].s, tests[i].v, &r, &g, &b);
-      g_assert_cmpfloat_with_epsilon (r, tests[i].r, FLT_EPSILON);
-      g_assert_cmpfloat_with_epsilon (g, tests[i].g, FLT_EPSILON);
-      g_assert_cmpfloat_with_epsilon (b, tests[i].b, FLT_EPSILON);
+      g_assert_cmpfloat_with_epsilon (r, tests[i].r, EPSILON);
+      g_assert_cmpfloat_with_epsilon (g, tests[i].g, EPSILON);
+      g_assert_cmpfloat_with_epsilon (b, tests[i].b, EPSILON);
       gtk_rgb_to_hsv (tests[i].r, tests[i].g, tests[i].b, &h, &s, &v);
-      g_assert_cmpfloat_with_epsilon (h, tests[i].h, FLT_EPSILON);
-      g_assert_cmpfloat_with_epsilon (s, tests[i].s, FLT_EPSILON);
-      g_assert_cmpfloat_with_epsilon (v, tests[i].v, FLT_EPSILON);
+      g_assert_cmpfloat_with_epsilon (h, tests[i].h, EPSILON);
+      g_assert_cmpfloat_with_epsilon (s, tests[i].s, EPSILON);
+      g_assert_cmpfloat_with_epsilon (v, tests[i].v, EPSILON);
     }
 }