[gnumeric] Compilation: numbers.h namespace cleanup.



commit bbcc3013e8de7e2f5bd5ebe172df688e8add220b
Author: Morten Welinder <terra gnome org>
Date:   Fri Nov 15 19:36:33 2013 -0500

    Compilation: numbers.h namespace cleanup.
    
    We don't want our HAVE_this or HAVE_that to make it into our API.

 configure.ac           |   37 +++++++++++++++++++++++++++++++++++--
 gnumeric-features.h.in |   19 ++++++++-----------
 src/mathfunc.c         |   30 +++++++++++++++---------------
 src/numbers.h          |   29 +++++++++++------------------
 4 files changed, 69 insertions(+), 46 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7ee29e1..f6c624e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -603,15 +603,29 @@ CFLAGS=$SAVE_CFLAGS
 LIBS=$SAVE_LIBS
 
 dnl We supply our own lgamma and lgamma_r when missing.
+supply_lgamma_r=yes
 AC_CHECK_FUNCS(lgamma_r)
 if test $ac_cv_func_lgamma_r = no; then
   AC_CHECK_LIB(m, lgamma_r,
         [AC_DEFINE(HAVE_LGAMMA_R, 1,
                [Define if the lgamma_r function is available]
         )
+        supply_lgamma_r=no
          LIBS="$LIBS -lm"])
+else
+  supply_lgamma_r=no
+fi
+if test $supply_lgamma_r = yes; then
+   AC_DEFINE(GNM_SUPPLIES_LGAMMA_R, 1,
+       [Define if Gnumeric supplies the lgamma_r function]
+       )
 fi
 AC_CHECK_FUNCS(lgamma)
+if test $ac_cv_func_lgamma = no; then
+   AC_DEFINE(GNM_SUPPLIES_LGAMMA, 1,
+       [Define if Gnumeric supplies the lgamma function]
+       )
+fi
 
 float_msg=double
 AC_ARG_WITH(long_double,
@@ -636,12 +650,15 @@ AC_ARG_WITH(long_double,
                                AC_MSG_ERROR([Long doubles require the $ldfunc function.]))
 
                AC_MSG_CHECKING([checking for working erfl and erfcl])
+               have_erfl=no
+               have_erfcl=no
                AC_RUN_IFELSE(
                        [AC_LANG_PROGRAM([[
                                #include <math.h>
                                #ifdef HAVE_SUNMATH_H
                                #include <sunmath.h>
-                               #endif]],
+                               #endif
+                               ]],
                                [[
                                        long double l1 = erfl (1.2L);
                                        long double l2 = erfcl (1.2L);
@@ -649,10 +666,26 @@ AC_ARG_WITH(long_double,
                                                 l2 >= 0.08 && l2 <= 0.09);
                                ]])],
                        [AC_DEFINE(HAVE_ERFL)
+                        have_erfl=yes
                         AC_DEFINE(HAVE_ERFCL)
+                        have_erfcl=yes
                        AC_MSG_RESULT(yes)],
                        AC_MSG_RESULT(no),
-                       [AC_CHECK_FUNCS(erfl erfcl)])
+                       [AC_CHECK_FUNCS(erfl erfcl)
+                       have_erfl=$ac_cv_func_erfl
+                       have_erfcl=$ac_cv_func_erfcl
+                       ])
+
+               if $have_erfl = no; then
+                       AC_DEFINE(GNM_SUPPLIES_ERFL, 1,
+                                [Define if Gnumeric supplies the erfl function]
+                                )
+               fi
+               if $have_erfcl = no; then
+                       AC_DEFINE(GNM_SUPPLIES_ERFCL, 1,
+                                [Define if Gnumeric supplies the erfcl function]
+                                )
+               fi
 
                CFLAGS="$SAVE_CFLAGS"
                LIBS="$SAVE_LIBS"
diff --git a/gnumeric-features.h.in b/gnumeric-features.h.in
index 3716cd8..a20a5e2 100644
--- a/gnumeric-features.h.in
+++ b/gnumeric-features.h.in
@@ -20,19 +20,16 @@
 /* Define if the long double type is to be used */
 #undef GNM_WITH_LONG_DOUBLE
 
-/* Define to 1 if you have the `lgamma' function. */
-#undef HAVE_LGAMMA
+/* Define to 1 if Gnumeric supplies the `lgamma' function. */
+#undef GNM_SUPPLIES_LGAMMA
 
-/* Define if the lgamma_r function is available */
-#undef HAVE_LGAMMA_R
+/* Define to 1 if Gnumeric supplies the `lgamma' function. */
+#undef GNM_SUPPLIES_LGAMMA_R
 
-/* Define to 1 if you have the `erfl' function. */
-#undef HAVE_ERFL
+/* Define to 1 if Gnumeric supplies the `erfl' function. */
+#undef GNM_SUPPLIES_ERFL
 
-/* Define to 1 if you have the `erfcl' function. */
-#undef HAVE_ERFCL
-
-/* Define to 1 if you have the `ynl' function. */
-#undef HAVE_YNL
+/* Define to 1 if Gnumeric supplies the `erfcl' function. */
+#undef GNM_SUPPLIES_ERFCL
 
 #endif  /* _LIBSPREADSHEET_CONFIG_H_ */
diff --git a/src/mathfunc.c b/src/mathfunc.c
index c62855d..c36ac20 100644
--- a/src/mathfunc.c
+++ b/src/mathfunc.c
@@ -8707,18 +8707,18 @@ gnm_matrix_eigen (GnmMatrix const *m, GnmMatrix *EIG, gnm_float *eigenvalues)
 
 /* ------------------------------------------------------------------------- */
 
-#ifdef NEED_FAKE_ERFGNUM
-gnm_float
-gnm_erf (gnm_float x)
+#ifdef GNM_SUPPLIES_ERFL
+long double
+erfl (long double x)
 {
-       if (gnm_abs (x) < 0.1) {
+       if (fabsl (x) < 0.125) {
                /* For small x the pnorm formula loses precision.  */
-               gnm_float sum = 0;
-               gnm_float term = x * 2 / gnm_sqrt (M_PIgnum);
-               gnm_float n;
-               gnm_float x2 = x * x;
+               long double sum = 0;
+               long double term = x * 2 / sqrtl (M_PIgnum);
+               long double n;
+               long double x2 = x * x;
 
-               for (n = 0; gnm_abs (term) >= gnm_abs (sum) * GNM_EPSILON ; n++) {
+               for (n = 0; fabsl (term) >= fabsl (sum) * LDBL_EPSILON ; n++) {
                        sum += term / (2 * n + 1);
                        term *= -x2 / (n + 1);
                }
@@ -8731,9 +8731,9 @@ gnm_erf (gnm_float x)
 
 /* ------------------------------------------------------------------------- */
 
-#ifdef NEED_FAKE_ERFCGNUM
-gnm_float
-gnm_erfc (gnm_float x)
+#ifdef GNM_SUPPLIES_ERFCL
+long double
+erfcl (long double x)
 {
        return 2 * pnorm (x * M_SQRT2gnum, 0, 1, FALSE, FALSE);
 }
@@ -8741,8 +8741,8 @@ gnm_erfc (gnm_float x)
 
 /* ------------------------------------------------------------------------- */
 
-#ifndef HAVE_LGAMMA
-/* Avoid using this.  It may be missing in system libraries.  */
+#ifdef GNM_SUPPLIES_LGAMMA
+/* Avoid using signgam.  It may be missing in system libraries.  */
 int signgam;
 
 double
@@ -8752,7 +8752,7 @@ lgamma (double x)
 }
 #endif
 
-#ifndef HAVE_LGAMMA_R
+#ifdef GNM_SUPPLIES_LGAMMA_R
 double
 lgamma_r (double x, int *signp)
 {
diff --git a/src/numbers.h b/src/numbers.h
index 26dc570..6ad65e0 100644
--- a/src/numbers.h
+++ b/src/numbers.h
@@ -12,36 +12,27 @@ G_BEGIN_DECLS
  * in gnumeric-features.h.in
  */
 
-#ifndef HAVE_LGAMMA
-/* Defined in mathfunc.c  */
+#ifdef GNM_SUPPLIES_LGAMMA
 GO_VAR_DECL int signgam;
 double lgamma (double x);
 #endif
-#ifndef HAVE_LGAMMA_R
-/* Defined in mathfunc.c  */
+
+#ifdef GNM_SUPPLIES_LGAMMA_R
 double lgamma_r (double x, int *signp);
 #endif
 
 #ifdef GNM_WITH_LONG_DOUBLE
 
-typedef long double gnm_float;
-
-#ifdef HAVE_ERFL
-#define gnm_erf erfl
-#else
-#define NEED_FAKE_ERFGNUM
-/* Defined in mathfunc.c  */
-gnm_float gnm_erf (gnm_float x);
+#ifdef GNM_SUPPLIES_ERFL
+long double erfl (long double x);
 #endif
 
-#ifdef HAVE_ERFCL
-#define gnm_erfc erfcl
-#else
-#define NEED_FAKE_ERFCGNUM
-/* Defined in mathfunc.c  */
-gnm_float gnm_erfc (gnm_float x);
+#ifdef GNM_SUPPLIES_ERFCL
+long double erfl (long double x);
 #endif
 
+typedef long double gnm_float;
+
 #define gnm_abs fabsl
 #define gnm_acos acosl
 #define gnm_acosh acoshl
@@ -54,6 +45,8 @@ gnm_float gnm_erfc (gnm_float x);
 #define gnm_ceil ceill
 #define gnm_cos cosl
 #define gnm_cosh coshl
+#define gnm_erf erfl
+#define gnm_erfc erfcl
 #define gnm_exp expl
 #define gnm_expm1 expm1l
 #define gnm_fake_ceil go_fake_ceill


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