[goffice] Math: use C99's nextafter when available.



commit 638c734e8c765730b7149bf8f55021587f2b595c
Author: Morten Welinder <terra gnome org>
Date:   Tue Dec 17 21:49:51 2013 -0500

    Math: use C99's nextafter when available.

 ChangeLog              |    3 +++
 configure.ac           |    2 ++
 goffice/math/go-math.c |   18 +++++++++++++++++-
 3 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6758a7c..605a227 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-12-17  Morten Welinder  <terra gnome org>
 
+       * goffice/math/go-math.c (go_add_epsilon, go_sub_epsilon): Base
+       upon C99's nextafter.
+
        * tests/test-quad.c (floor_tests): Test asin and acos.
 
        * goffice/math/go-quad.c (go_quad_acos, go_quad_asin): new
diff --git a/configure.ac b/configure.ac
index a252e57..254ff75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -544,6 +544,8 @@ if test $ac_cv_func_log = no; then
          LIBS="$LIBS -lm"])
 fi
 
+AC_CHECK_FUNCS(nextafter nextafterl)
+
 SAVE_CFLAGS=$CFLAGS
 SAVE_LIBS=$LIBS
 CFLAGS="$CFLAGS $GOFFICE_CFLAGS"
diff --git a/goffice/math/go-math.c b/goffice/math/go-math.c
index 0ca4bb3..c4545b2 100644
--- a/goffice/math/go-math.c
+++ b/goffice/math/go-math.c
@@ -64,7 +64,7 @@ running_under_buggy_valgrind (void)
                return FALSE;
 
        /*
-        * We get here is long double fails to satisfy a requirement of
+        * We get here when long double fails to satisfy a requirement of
         * C99, namely that LDBL_MIN is positive.  That is probably
         * valgrind mapping long doubles to doubles.
         *
@@ -212,6 +212,9 @@ _go_math_init (void)
 double
 go_add_epsilon (double x)
 {
+#ifdef HAVE_NEXTAFTER
+       return x == 0 ? x : nextafter (x, go_pinf);
+#else
        if (!go_finite (x) || x == 0)
                return x;
        else {
@@ -220,11 +223,15 @@ go_add_epsilon (double x)
                double absres = ldexp (mant + DBL_EPSILON, exp);
                return (x < 0) ? -absres : absres;
        }
+#endif
 }
 
 double
 go_sub_epsilon (double x)
 {
+#ifdef HAVE_NEXTAFTER
+       return x == 0 ? x : nextafter (x, go_ninf);
+#else
        if (!go_finite (x) || x == 0)
                return x;
        else {
@@ -233,6 +240,7 @@ go_sub_epsilon (double x)
                double absres = ldexp (mant - DBL_EPSILON, exp);
                return (x < 0) ? -absres : absres;
        }
+#endif
 }
 
 static double
@@ -648,6 +656,9 @@ go_ascii_strtold (const char *s, char **end)
 long double
 go_add_epsilonl (long double x)
 {
+#ifdef HAVE_NEXTAFTERL
+       return x == 0 ? x : nextafterl (x, go_pinfl);
+#else
        if (!go_finitel (x) || x == 0)
                return x;
        else {
@@ -656,11 +667,15 @@ go_add_epsilonl (long double x)
                long double absres = ldexpl (mant + LDBL_EPSILON, exp);
                return (x < 0) ? -absres : absres;
        }
+#endif
 }
 
 long double
 go_sub_epsilonl (long double x)
 {
+#ifdef HAVE_NEXTAFTERL
+       return x == 0 ? x : nextafterl (x, go_ninfl);
+#else
        if (!go_finitel (x) || x == 0)
                return x;
        else {
@@ -669,6 +684,7 @@ go_sub_epsilonl (long double x)
                long double absres = ldexpl (mant - LDBL_EPSILON, exp);
                return (x < 0) ? -absres : absres;
        }
+#endif
 }
 
 long double


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