Fix detection and usage of mpc in newer versions (like mpc 0.9)
authorNelson Ferreira <nelson.ferreira@ieee.org>
Sat, 3 Dec 2011 08:02:40 +0000 (03:02 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Sat, 3 Dec 2011 08:02:40 +0000 (03:02 -0500)
* m4/sxe-maths.m4 (_SXE_CHECK_MPC): check for mpc_init and
mpc_set_ui_fr which were recently removed so that they can be
emulated for now. Also determine if mpc can be inited (and thus
used) by making sure one of mpc_init or mpc_init2 is available.

* m4/sxe-maths.m4 (SXE_CHECK_MPC_LIBS): check for mpc_init2 and
mpc_set_ui_fr too.

* src/ent/ent-mpc.h (bigc_init): conditional definition on whether
mpc_init or mpc_init2 is available.

* src/ent/ent-mpc.c: define mpc_set_ui_fr based on the MPC_SET_X_Y
macro if available. Abort compile if not available.

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
m4/sxe-maths.m4
src/ent/ent-mpc.c
src/ent/ent-mpc.h

index e1f7aba..3bf2a02 100644 (file)
@@ -672,13 +672,23 @@ AC_DEFUN([_SXE_CHECK_MPC], [dnl
        AC_REQUIRE([SXE_CHECK_MPC_LIBS])
        SXE_RESTORE_LIBS
 
+       if test "$ac_cv_lib_mpc_mpc_init" = "yes"; then
+               AC_DEFINE([HAVE_MPC_INIT], [1], [Whether simple mpc_init is available])
+       fi
+       if test "$ac_cv_lib_mpc_mpc_set_ui_fr" = "yes"; then
+               AC_DEFINE([HAVE_MPC_SET_UI_FR], [1], [Whether simple mpc_set_ui_fr is available])
+       fi
+       if test "$ac_cv_lib_mpc_mpc_init" = "yes" -o \
+               "$ac_cv_lib_mpc_mpc_init2" = "yes"; then
+               mpc_can_be_initted="yes"
+       fi
        if test "$ac_cv_header_mpc_h" = "yes" -a \
-               "$ac_cv_lib_mpc_mpc_init" = "yes" -a \
+               "$mpc_can_be_initted" = "yes" -a \
                "$mpc_doth_need_mpfr" = "yes"; then
                sxe_cv_feat_mpc="yes"
                MPC_LIBS="-lmpfr -lmpc"
        elif test "$ac_cv_header_mpc_h" = "yes" -a \
-               "$ac_cv_lib_mpc_mpc_init" = "yes" -a \
+               "$mpc_can_be_initted" = "yes" -a \
                "$mpc_doth_need_mpfr" = "no"; then
                sxe_cv_feat_mpc="yes"
                MPC_LIBS="-lmpc"
@@ -703,12 +713,16 @@ AC_DEFUN([SXE_CHECK_MPC_LIBS], [dnl
        AC_REQUIRE([SXE_CHECK_MPFR_LIBS])
        if test "$ac_cv_lib_mpfr_mpfr_init" = "yes"; then
                AC_CHECK_LIB([mpc], [mpc_init], [:], [:], [-lmpfr])
+               AC_CHECK_LIB([mpc], [mpc_init2], [:], [:], [-lmpfr])
+               AC_CHECK_LIB([mpc], [mpc_set_ui_fr], [:], [:], [-lmpfr])
                mpc_doth_need_mpfr="yes"
        else
                ## try without mpfr.h, but this is definitely going to fail
                ## unless you're a developer of mpc ...
-               ## ... and in that case: Fix teh MPC build chain, Andreas!!!
+               ## ... and in that case: Fix the MPC build chain, Andreas!!!
                AC_CHECK_LIB([mpc], [mpc_init], [:])
+               AC_CHECK_LIB([mpc], [mpc_init2], [:])
+               AC_CHECK_LIB([mpc], [mpc_set_ui_fr], [:])
                mpc_doth_need_mpfr="no"
        fi
 ])dnl SXE_CHECK_MPC_LIBS
index eaf9318..e10f8a4 100644 (file)
@@ -76,6 +76,15 @@ static const struct lrecord_description bigc_description[] = {
        { XD_END }
 };
 
+#if ! HAVE_MPC_SET_UI_FR
+#if defined(MPC_SET_X_Y)
+int mpc_set_ui_fr (mpc_t rop, unsigned long int re, mpfr_t im, mpc_rnd_t rnd)
+              MPC_SET_X_Y (ui, fr, rop, re, im, rnd);
+#else
+#error Cannot derived mpc_set_ui_fr without MPC_SET_X_Y!
+#endif
+#endif
+
 DEFINE_BASIC_LRECORD_IMPLEMENTATION("bigc", bigc,
                                    bigc_mark, bigc_print, bigc_finalise,
                                    bigc_equal, bigc_hash,
index 2adcac1..f488ae6 100644 (file)
@@ -88,19 +88,22 @@ extern bigc ent_scratch_bigc;
 \f
 /********************************* Bigcs ********************************/
 
-#define HAVE_MPC 1
 
 /***** Bigc: basic functions *****/
+#if HAVE_MPC_INIT
 #define bigc_init(f)                mpc_init(f)
-#define bigc_init_prec(f,prec)      mpc_init2(f, prec)
-#define bigc_init_2prec(f,p1,p2)    mpc_init3(f, p1, p2)
+#else
+#define bigc_init(f)                mpc_init2((f),internal_get_precision(Qnil))
+#endif
+#define bigc_init_prec(f,prec)      mpc_init2((f), (prec))
+#define bigc_init_2prec(f,p1,p2)    mpc_init3((f), (p1), (p2))
 #define bigc_fini(f)                mpc_clear(f)
 #define bigc_hashcode(f)            (bigfr_hashcode(bigc_re(f)) ^ \
                                     bigfr_hashcode(bigc_im(f)))
 #define bigc_get_prec(f)            max(bigfr_get_prec(bigc_re(f)), \
                                        bigfr_get_prec(bigc_im(f)))
-#define bigc_set_prec(f, prec)      mpc_set_prec(f, prec)
-#define bigc_set_default_prec(prec) mpc_set_default_prec(prec)
+#define bigc_set_prec(f, prec)      mpc_set_prec((f), (prec))
+#define bigc_set_default_prec(prec) mpc_set_default_prec((prec))
 #define bigc_get_default_prec()     mpc_get_default_prec()
 
 /***** Bigc: conversions *****/