diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-05-19 08:03:19 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-05-19 08:03:19 +0000 |
commit | e12bca0a70f223e153f9326472b63ac4a877a277 (patch) | |
tree | 924a92085194c702513ba69f86f4751e3ec24a42 | |
parent | 5be776e2da15610c73a6e149d95663943b7d0a4d (diff) | |
download | mpfr-e12bca0a70f223e153f9326472b63ac4a877a277.tar.gz |
more work on MPFR_TESTS_EXCEPTIONS
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11492 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | tests/tcmp_d.c | 2 | ||||
-rw-r--r-- | tests/tcmp_ld.c | 2 | ||||
-rw-r--r-- | tests/td_div.c | 3 | ||||
-rw-r--r-- | tests/tests.c | 22 | ||||
-rw-r--r-- | tests/tget_d.c | 8 | ||||
-rw-r--r-- | tests/tget_d_2exp.c | 2 | ||||
-rw-r--r-- | tests/tget_flt.c | 8 | ||||
-rw-r--r-- | tests/tget_ld_2exp.c | 2 | ||||
-rw-r--r-- | tests/tset_d.c | 4 | ||||
-rw-r--r-- | tests/tset_float128.c | 6 | ||||
-rw-r--r-- | tests/tset_ld.c | 6 |
11 files changed, 37 insertions, 28 deletions
diff --git a/tests/tcmp_d.c b/tests/tcmp_d.c index 00fc5e987..75b233ae1 100644 --- a/tests/tcmp_d.c +++ b/tests/tcmp_d.c @@ -80,7 +80,7 @@ main (void) } set_emin (emin); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) /* Check NAN */ { int c; diff --git a/tests/tcmp_ld.c b/tests/tcmp_ld.c index dbe6957db..89ef2c834 100644 --- a/tests/tcmp_ld.c +++ b/tests/tcmp_ld.c @@ -82,7 +82,7 @@ main (void) } set_emin (emin); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) /* Check NAN */ { int c; diff --git a/tests/td_div.c b/tests/td_div.c index e3ca3e434..c15ebf26a 100644 --- a/tests/td_div.c +++ b/tests/td_div.c @@ -59,7 +59,7 @@ check_nans (void) MPFR_ASSERTN (mpfr_zero_p (y)); MPFR_ASSERTN (MPFR_IS_NEG (y)); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) /* 1.0 / 0 == +inf */ mpfr_set_ui (x, 0, MPFR_RNDN); @@ -136,7 +136,6 @@ check_nans (void) MPFR_ASSERTN (__gmpfr_flags == 0); MPFR_ASSERTN (mpfr_inf_p (y)); MPFR_ASSERTN (MPFR_IS_POS (y)); - #endif mpfr_clear (x); diff --git a/tests/tests.c b/tests/tests.c index 274d30884..784a6e2df 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -32,6 +32,9 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #endif #if defined(MPFR_TESTS_DIVBYZERO) || defined(MPFR_TESTS_EXCEPTIONS) +#ifdef MPFR_RAISE_EXCEPTIONS +#define _GNU_SOURCE /* for feenableexcept */ +#endif # include <fenv.h> #endif @@ -235,6 +238,13 @@ test_version (void) exit (1); } +/* The inexact exception occurs very often, and is normal. + The underflow exception also might occur, for example in test_generic + for mpfr_xxx_d functions. Same for overflow. Thus we only check for + the division-by-zero and invalid exceptions, which should not occur + inside MPFR. */ +#define EXCEPTIONS_FLAG (FE_DIVBYZERO | FE_INVALID) + void tests_start_mpfr (void) { @@ -257,6 +267,10 @@ tests_start_mpfr (void) #if defined(MPFR_TESTS_DIVBYZERO) || defined(MPFR_TESTS_EXCEPTIONS) /* Define to test the use of MPFR_ERRDIVZERO */ feclearexcept (FE_ALL_EXCEPT); + /* to raise exceptions as soon as they arise, use feenableexcept */ +#ifdef MPFR_RAISE_EXCEPTIONS + feenableexcept (EXCEPTIONS_FLAG); +#endif #endif if (!tests_memory_disabled) @@ -292,9 +306,9 @@ tests_end_mpfr (void) tests_memory_end (); #if defined(MPFR_TESTS_DIVBYZERO) || defined(MPFR_TESTS_EXCEPTIONS) - if (fetestexcept (FE_ALL_EXCEPT ^ FE_INEXACT)) + if (fetestexcept (EXCEPTIONS_FLAG)) { - printf ("A floating-point exception occurred:"); + printf ("Some floating-point exception(s) occurred:"); if (fetestexcept (FE_DIVBYZERO)) { printf (" DIVBYZERO"); @@ -314,10 +328,6 @@ tests_end_mpfr (void) err = 1; #endif } - if (fetestexcept (FE_OVERFLOW)) - printf (" OVERFLOW"); - if (fetestexcept (FE_UNDERFLOW)) - printf (" UNDERFLOW"); printf ("\n"); #ifdef MPFR_TESTS_EXCEPTIONS err = 1; diff --git a/tests/tget_d.c b/tests/tget_d.c index 618093dab..6dc552a03 100644 --- a/tests/tget_d.c +++ b/tests/tget_d.c @@ -89,7 +89,7 @@ static void check_inf_nan (void) { /* only if nans and infs are available */ -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) mpfr_t x; double d; @@ -139,7 +139,7 @@ check_max (void) MPFR_ASSERTN(d == -DBL_MAX); d = mpfr_get_d (u, MPFR_RNDU); MPFR_ASSERTN(d == -DBL_MAX); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) d = mpfr_get_d (u, MPFR_RNDN); MPFR_ASSERTN(DOUBLE_ISINF(d) && d < 0.0); d = mpfr_get_d (u, MPFR_RNDD); @@ -151,7 +151,7 @@ check_max (void) MPFR_ASSERTN(d == DBL_MAX); d = mpfr_get_d (u, MPFR_RNDD); MPFR_ASSERTN(d == DBL_MAX); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) d = mpfr_get_d (u, MPFR_RNDN); MPFR_ASSERTN(DOUBLE_ISINF(d) && d > 0.0); d = mpfr_get_d (u, MPFR_RNDU); @@ -185,7 +185,7 @@ check_min(void) static void check_get_d_2exp_inf_nan (void) { -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) double var_d; long exp; diff --git a/tests/tget_d_2exp.c b/tests/tget_d_2exp.c index 8cf6af5ff..a7ebb330e 100644 --- a/tests/tget_d_2exp.c +++ b/tests/tget_d_2exp.c @@ -78,7 +78,7 @@ check_round (void) static void check_inf_nan (void) { -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) mpfr_t x; double d; long exp; diff --git a/tests/tget_flt.c b/tests/tget_flt.c index 778cc6800..2e08d9aca 100644 --- a/tests/tget_flt.c +++ b/tests/tget_flt.c @@ -36,7 +36,7 @@ main (void) tests_start_mpfr (); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) /* The definition of DBL_POS_INF involves a division by 0. This makes "clang -O2 -fsanitize=undefined -fno-sanitize-recover" fail. */ infp = (float) DBL_POS_INF; @@ -51,7 +51,7 @@ main (void) mpfr_init2 (x, 24); mpfr_init2 (y, 24); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) mpfr_set_nan (x); f = mpfr_get_flt (x, MPFR_RNDN); if (! DOUBLE_ISNAN (f)) @@ -320,7 +320,7 @@ main (void) printf ("expected %.8e, got %.8e\n", g, f); exit (1); } -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) f = mpfr_get_flt (x, MPFR_RNDN); /* 2^128 rounds to itself with extended exponent range, we should get +Inf */ g = infp; @@ -365,7 +365,7 @@ main (void) printf ("expected %.8e, got %.8e\n", g, f); exit (1); } -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) f = mpfr_get_flt (x, MPFR_RNDN); /* first round to 2^128 (even rule), thus we should get +Inf */ g = infp; diff --git a/tests/tget_ld_2exp.c b/tests/tget_ld_2exp.c index d1f0511a2..5ee1e8936 100644 --- a/tests/tget_ld_2exp.c +++ b/tests/tget_ld_2exp.c @@ -77,7 +77,7 @@ check_round (void) static void check_inf_nan (void) { -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) mpfr_t x; double d; long exp; diff --git a/tests/tset_d.c b/tests/tset_d.c index 3da550788..35fce372b 100644 --- a/tests/tset_d.c +++ b/tests/tset_d.c @@ -63,7 +63,7 @@ main (int argc, char *argv[]) mpfr_init (x); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) mpfr_set_nan (x); d = mpfr_get_d (x, MPFR_RNDN); if (! DOUBLE_ISNAN (d)) @@ -105,7 +105,7 @@ main (int argc, char *argv[]) } #endif /* HAVE_SIGNEDZ */ -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) mpfr_set_inf (x, 1); d = mpfr_get_d (x, MPFR_RNDN); mpfr_set_ui (x, 0, MPFR_RNDN); diff --git a/tests/tset_float128.c b/tests/tset_float128.c index 7d6b0a7a5..d1a92bffe 100644 --- a/tests/tset_float128.c +++ b/tests/tset_float128.c @@ -40,7 +40,7 @@ check_special (void) mpfr_init2 (x, 113); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) /* check NaN */ f = 0.0 / 0.0; mpfr_set_float128 (x, f, MPFR_RNDN); @@ -102,7 +102,7 @@ check_special (void) printf ("Error in mpfr_get_float128(+0.0)\n"); exit (1); } -#if !defined(MPFR_ERRDIVZERO) && defined(HAVE_SIGNEDZ) +#if !defined(MPFR_ERRDIVZERO) && defined(HAVE_SIGNEDZ) && !defined(MPFR_TESTS_EXCEPTIONS) if (1 / f != 1 / 0.0) /* check the sign */ { printf ("Error in mpfr_get_float128(+0.0)\n"); @@ -131,7 +131,7 @@ check_special (void) printf ("Error in mpfr_get_float128(-0.0)\n"); exit (1); } -#if !defined(MPFR_ERRDIVZERO) && defined(HAVE_SIGNEDZ) +#if !defined(MPFR_ERRDIVZERO) && defined(HAVE_SIGNEDZ) && !defined(MPFR_TESTS_EXCEPTIONS) if (1 / f != 1 / -0.0) /* check the sign */ { printf ("Error in mpfr_get_float128(-0.0)\n"); diff --git a/tests/tset_ld.c b/tests/tset_ld.c index b0e1d9e08..61fc82b9a 100644 --- a/tests/tset_ld.c +++ b/tests/tset_ld.c @@ -73,7 +73,7 @@ print_binary (long double d, int flag) return 0; } if (d < (long double) 0.0 -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) || (d == (long double) 0.0 && (1.0 / (double) d < 0.0)) #endif ) @@ -506,7 +506,7 @@ main (int argc, char *argv[]) mpfr_init2 (x, MPFR_LDBL_MANT_DIG + 64); -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) /* check NaN */ mpfr_set_nan (x); d = mpfr_get_ld (x, MPFR_RNDN); @@ -532,7 +532,7 @@ main (int argc, char *argv[]) #endif } -#if !defined(MPFR_ERRDIVZERO) +#if !defined(MPFR_ERRDIVZERO) && !defined(MPFR_TESTS_EXCEPTIONS) /* check +Inf */ mpfr_set_inf (x, 1); d = mpfr_get_ld (x, MPFR_RNDN); |