[gnome-photos] build, utils: Adjust how the floating point tolerance is defined



commit 31fc31a1b8607a68bc0adc09fd54fe486d3d191d
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Aug 16 21:25:58 2018 +0200

    build, utils: Adjust how the floating point tolerance is defined
    
    A subsequent commit will switch to using G_APPROX_VALUE instead of
    photos_utils_equal_double. Since G_APPROX_VALUE requires specifying the
    tolerance value, it would be convenient to have it defined somewhere
    that's already accessible to every source file to avoid having to
    #include a separate header to compare floating point values. Every
    source file already #includes config.h, so that's the natural choice.

 configure.ac       | 2 ++
 src/photos-utils.c | 5 +----
 2 files changed, 3 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7c1a45f3..4c2c3814 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,8 @@ AM_GNU_GETTEXT_VERSION([0.19.8])
 AX_REQUIRE_DEFINED([AM_GNU_GETTEXT])
 AM_GNU_GETTEXT([external])
 
+AC_DEFINE([PHOTOS_EPSILON], [1e-5], [Tolerance when comparing single or double precision floating point 
values])
+
 LT_INIT
 
 AC_CHECK_LIB([jpeg], [jpeg_destroy_decompress], , AC_MSG_ERROR([JPEG library not found]))
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 9a947950..5bad09ac 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -69,9 +69,6 @@
 #include "photos-utils.h"
 
 
-static const gdouble EPSILON = 1e-5;
-
-
 GdkPixbuf *
 photos_utils_center_pixbuf (GdkPixbuf *pixbuf, gint size)
 {
@@ -779,7 +776,7 @@ gboolean
 photos_utils_equal_double (gdouble a, gdouble b)
 {
   const gdouble diff = a - b;
-  return diff > -EPSILON && diff < EPSILON;
+  return diff > -PHOTOS_EPSILON && diff < PHOTOS_EPSILON;
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]