summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2008-08-12 21:47:44 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2008-08-12 21:47:44 +0000
commit7e2690e853e233689ce018e6177c7772ddce2460 (patch)
tree539479c04950c1fc9ceaa57a4924f7c003ce054d /tests
parent8ae3d81a1db288ff775c0f18c0197a8cc580b93f (diff)
downloadmpfr-7e2690e853e233689ce018e6177c7772ddce2460.tar.gz
tests/tdiv.c: added a test that triggers a bug in mpfr_div in case of
underflow in rounding to nearest when the result must be non-zero. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@5514 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r--tests/tdiv.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/tests/tdiv.c b/tests/tdiv.c
index 6cf099ac9..b9a92f448 100644
--- a/tests/tdiv.c
+++ b/tests/tdiv.c
@@ -626,6 +626,7 @@ check_nan (void)
{
mpfr_t a, d, q;
mp_exp_t emax, emin;
+ int i;
mpfr_init2 (a, 100L);
mpfr_init2 (d, 100L);
@@ -718,11 +719,29 @@ check_nan (void)
set_emin (-1);
mpfr_set_ui (a, 1, GMP_RNDZ);
mpfr_div_2exp (a, a, 2, GMP_RNDZ);
- mpfr_set_ui (d, 2, GMP_RNDZ);
- test_div (q, a, d, GMP_RNDZ); /* 0.5*2^(-2) -> underflow */
- MPFR_ASSERTN (mpfr_cmp_ui (q, 0) == 0 && MPFR_IS_POS (q));
- test_div (q, a, d, GMP_RNDN); /* 0.5*2^(-2) -> underflow */
- MPFR_ASSERTN (mpfr_cmp_ui (q, 0) == 0 && MPFR_IS_POS (q));
+ mpfr_set_prec (d, mpfr_get_prec (q) + 8);
+ for (i = -1; i <= 1; i++)
+ {
+ /* Test 2^(-2) / (2 + eps), with eps < 0, eps = 0, eps > 0.
+ -> underflow.
+ With div.c r5513, this test fails for eps < 0 in GMP_RNDN. */
+ mpfr_set_ui (d, 2, GMP_RNDZ);
+ if (i < 0)
+ mpfr_nextbelow (d);
+ if (i > 0)
+ mpfr_nextabove (d);
+ mpfr_clear_flags ();
+ test_div (q, a, d, GMP_RNDZ); /* result = 0 */
+ MPFR_ASSERTN (mpfr_underflow_p ());
+ MPFR_ASSERTN (MPFR_IS_ZERO (q) && MPFR_IS_POS (q));
+ mpfr_clear_flags ();
+ test_div (q, a, d, GMP_RNDN); /* result = 0 iff eps >= 0 */
+ MPFR_ASSERTN (mpfr_underflow_p ());
+ MPFR_ASSERTN (MPFR_IS_POS (q));
+ if (i < 0)
+ mpfr_nextbelow (q);
+ MPFR_ASSERTN (MPFR_IS_ZERO (q));
+ }
set_emin (emin);
mpfr_clear (a);