summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in7
-rw-r--r--eint.c5
-rw-r--r--erfc.c5
-rw-r--r--mpfr-impl.h18
4 files changed, 31 insertions, 4 deletions
diff --git a/configure.in b/configure.in
index 2d9d8bfb9..4570357de 100644
--- a/configure.in
+++ b/configure.in
@@ -83,6 +83,13 @@ AC_ARG_ENABLE(thread-safe,
no) ;;
*) AC_MSG_ERROR([bad value for --enable-thread-safe: yes or no]) ;;
esac])
+AC_ARG_ENABLE(warnings,
+ [ --enable-warnings allow MPFR to output warnings to stderr [[default=no]]],
+ [ case $enableval in
+ yes) AC_DEFINE([MPFR_USE_WARNINGS],1,[Allow MPFR to output warnings to stderr]) ;;
+ no) ;;
+ *) AC_MSG_ERROR([bad value for --enable-warnings: yes or no]) ;;
+ esac])
AC_ARG_ENABLE(decimal-float,
[ --enable-decimal-float build conversion functions from/to decimal floats [[default=no]]],
[ case $enableval in
diff --git a/eint.c b/eint.c
index 099f67060..c70e1d9f3 100644
--- a/eint.c
+++ b/eint.c
@@ -19,7 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301, USA. */
-#include <stdio.h>
+#include <stdio.h> /* for MPFR_WARNING */
+#include <stdlib.h> /* for MPFR_WARNING */
#include <limits.h>
#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
@@ -232,7 +233,7 @@ mpfr_eint (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd)
/* FIXME: Improve the algorithm to be able to compute the actual
value. For the time being, we regard this as a range error,
so that the caller can cleanly deal with the problem. */
- fprintf (stderr, "MPFR: Error, too large input in mpfr_eint\n");
+ MPFR_WARNING ("Too large input in mpfr_eint, returning NaN");
MPFR_ZIV_FREE (loop);
mpfr_clear (tmp);
mpfr_clear (ump);
diff --git a/erfc.c b/erfc.c
index 24f4abaff..65a5983b0 100644
--- a/erfc.c
+++ b/erfc.c
@@ -19,7 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301, USA. */
-#include <stdio.h> /* for fprintf and stderr */
+#include <stdio.h> /* for MPFR_WARNING */
+#include <stdlib.h> /* for MPFR_WARNING */
#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
@@ -62,7 +63,7 @@ mpfr_erfc (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd)
/* FIXME: Improve the algorithm to be able to compute the actual
value. For the time being, we regard this as a range error,
so that the caller can cleanly deal with the problem. */
- fprintf (stderr, "MPFR: Error, too large input in mpfr_erfc\n");
+ MPFR_WARNING ("Too large input in mpfr_erfc, returning NaN");
MPFR_SET_ERANGE ();
MPFR_SET_NAN (y);
MPFR_RET_NAN;
diff --git a/mpfr-impl.h b/mpfr-impl.h
index b3f19eff8..3d2854a69 100644
--- a/mpfr-impl.h
+++ b/mpfr-impl.h
@@ -280,6 +280,24 @@ __MPFR_DECLSPEC extern const mpfr_t __gmpfr_four;
#define MPFR_RET_NEVER_GO_HERE() {MPFR_ASSERTN(0); return 0;}
+/******************************************************
+ ******************** Warnings ************************
+ ******************************************************/
+
+#ifdef MPFR_USE_WARNINGS
+/* Note: needs <stdio.h> and <stdlib.h> */
+# define MPFR_WARNING(W) \
+ do \
+ { \
+ char *q = getenv ("MPFR_QUIET"); \
+ if (q == NULL || *q == 0) \
+ fprintf (stderr, "MPFR: %s\n", W); \
+ } \
+ while (0)
+#else
+# define MPFR_WARNING(W) ((void) 0)
+#endif
+
/******************************************************
****************** double macros *********************