From cd2fb9c3fb3087e260712fd3a00d3ae4f5d0c814 Mon Sep 17 00:00:00 2001 From: vlefevre Date: Wed, 10 Jan 2018 16:38:44 +0000 Subject: [tests/tgeneric.c] Tests in a reduced exponent range: * Do several overflow/underflow tests instead of 1, and this for each precision. This allows one to detect 2 bugs (fixed in the trunk) that did not handle reduced exponent ranges correctly: - in mpfr_ai, making tai fail; - in mpfr_lgamma, making tlgamma hang with a 32-bit ABI. * Added some comments. (merged changesets r12087-12088 from the trunk) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@12093 280ebfd0-de03-0410-8827-d642c229c3f4 --- tests/tgeneric.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/tgeneric.c b/tests/tgeneric.c index 2e3c54098..942987498 100644 --- a/tests/tgeneric.c +++ b/tests/tgeneric.c @@ -157,7 +157,6 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) int inexact, compare, compare2; unsigned int n; unsigned long ctrt = 0, ctrn = 0; - int test_of = 1, test_uf = 1; mpfr_exp_t old_emin, old_emax; old_emin = mpfr_get_emin (); @@ -171,6 +170,12 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) /* generic test */ for (prec = p0; prec <= p1; prec++) { + /* Number of overflow/underflow tests for each precision. + Since MPFR uses several algorithms and there may also be + early overflow/underflow detection, several tests may be + needed to detect a bug. */ + int test_of = 3, test_uf = 3; + mpfr_set_prec (z, prec); mpfr_set_prec (t, prec); yprec = prec + 10; @@ -423,11 +428,15 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) #endif if (MPFR_IS_PURE_FP (y)) { - e = MPFR_GET_EXP (y); - if (test_of && e - 1 >= emax) + e = MPFR_GET_EXP (y); /* exponent of the result */ + + if (test_of > 0 && e - 1 >= emax) /* overflow test */ { mpfr_flags_t ex_flags; + /* Exponent e of the result > exponents of the inputs; + let's set emax to e - 1, so that one should get an + overflow. */ mpfr_set_emax (e - 1); #ifdef MPFR_DEBUG_TGENERIC printf ("tgeneric: overflow test (emax = %" @@ -481,12 +490,16 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) mpfr_dump (w); exit (1); } - test_of = 0; /* Overflow is tested only once. */ + test_of--; } - if (test_uf && e + 1 <= emin) + + if (test_uf > 0 && e + 1 <= emin) /* underflow test */ { mpfr_flags_t ex_flags; + /* Exponent e of the result < exponents of the inputs; + let's set emin to e + 1, so that one should get an + underflow. */ mpfr_set_emin (e + 1); #ifdef MPFR_DEBUG_TGENERIC printf ("tgeneric: underflow test (emin = %" @@ -540,15 +553,18 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) mpfr_dump (w); exit (1); } - test_uf = 0; /* Underflow is tested only once. */ + test_uf--; } + if (e < emin) emin = e; if (e > emax) emax = e; - } + } /* MPFR_IS_PURE_FP (y) */ + if (emin > emax) emin = emax; /* case where all values are singular */ + /* Consistency test in a reduced exponent range. Doing it for the first 10 samples and for prec == p1 (which has some special cases) should be sufficient. */ @@ -609,8 +625,9 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) exit (1); } } + __gmpfr_flags = oldflags; /* restore the flags */ - } + } /* tests in a reduced exponent range */ if (MPFR_IS_SINGULAR (y)) { -- cgit v1.2.1