diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-02-17 16:53:57 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-02-17 16:53:57 +0000 |
commit | 59cdcc7a8e532fad1efdf03bff4e925755453a70 (patch) | |
tree | a6cf0b794ebd0bb5a269ad3de0f1223183888b0e /tests/tsqrt.c | |
parent | 2bb722757f45d508ee2cf227ef8c6a93d4392b0f (diff) | |
download | mpfr-59cdcc7a8e532fad1efdf03bff4e925755453a70.tar.gz |
[tests/tsqrt.c] improve coverage
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12293 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tsqrt.c')
-rw-r--r-- | tests/tsqrt.c | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/tests/tsqrt.c b/tests/tsqrt.c index 572874824..6d86e5ba2 100644 --- a/tests/tsqrt.c +++ b/tests/tsqrt.c @@ -742,17 +742,89 @@ check_underflow (void) mpfr_init2 (u, p); mpfr_set_ui_2exp (u, 1, mpfr_get_emin () - 1, MPFR_RNDN); /* u = 2 */ /* for RNDN, since sqrt(2) is closer from 2 than 0, the result is 2 */ + mpfr_clear_flags (); inex = mpfr_sqrt (r, u, MPFR_RNDN); MPFR_ASSERTN(inex > 0); MPFR_ASSERTN(mpfr_equal_p (r, u)); - /* for RNDA, the result should be u */ + MPFR_ASSERTN(mpfr_underflow_p ()); + /* for RNDA, the result should be u, and there is underflow for p > 1, + since for p=1 we have 1 < sqrt(2) < 2, but for p >= 2, sqrt(2) should + be rounded to a number <= 1.5, which is representable */ + mpfr_clear_flags (); inex = mpfr_sqrt (r, u, MPFR_RNDA); MPFR_ASSERTN(inex > 0); MPFR_ASSERTN(mpfr_equal_p (r, u)); + MPFR_ASSERTN((p == 1 && !mpfr_underflow_p ()) || + (p != 1 && mpfr_underflow_p ())); /* for RNDZ, the result should be +0 */ + mpfr_clear_flags (); inex = mpfr_sqrt (r, u, MPFR_RNDZ); MPFR_ASSERTN(inex < 0); MPFR_ASSERTN(mpfr_zero_p (r) && mpfr_signbit (r) == 0); + MPFR_ASSERTN(mpfr_underflow_p ()); + + /* generate an input u such that sqrt(u) < 0.5*2^emin but there is no + underflow since sqrt(u) >= pred(0.5*2^emin), thus u >= 2^(2emin-2) */ + mpfr_set_ui_2exp (u, 1, 2 * mpfr_get_emin () - 2, MPFR_RNDN); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDN); + MPFR_ASSERTN(inex == 0); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(!mpfr_underflow_p ()); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDA); + MPFR_ASSERTN(inex == 0); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(!mpfr_underflow_p ()); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDZ); + MPFR_ASSERTN(inex == 0); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(!mpfr_underflow_p ()); + + /* next number */ + mpfr_set_ui_2exp (u, 1, 2 * mpfr_get_emin () - 2, MPFR_RNDN); + mpfr_nextabove (u); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDN); + MPFR_ASSERTN(inex < 0); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(!mpfr_underflow_p ()); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDA); + MPFR_ASSERTN(inex > 0); + mpfr_nextbelow (r); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(!mpfr_underflow_p ()); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDZ); + MPFR_ASSERTN(inex < 0); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(!mpfr_underflow_p ()); + + /* previous number */ + mpfr_set_ui_2exp (u, 1, 2 * mpfr_get_emin () - 2, MPFR_RNDN); + mpfr_nextbelow (u); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDN); + MPFR_ASSERTN(inex > 0); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + /* since sqrt(u) is just below the middle between 0.5*2^emin and + the previous number (with unbounded exponent range), there is + underflow */ + MPFR_ASSERTN(mpfr_underflow_p ()); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDA); + MPFR_ASSERTN(inex > 0); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(!mpfr_underflow_p ()); + mpfr_clear_flags (); + inex = mpfr_sqrt (r, u, MPFR_RNDZ); + MPFR_ASSERTN(inex < 0); + mpfr_nextabove (r); + MPFR_ASSERTN(mpfr_cmp_ui_2exp (r, 1, mpfr_get_emin () - 1) == 0); + MPFR_ASSERTN(mpfr_underflow_p ()); + mpfr_clear (r); mpfr_clear (u); } |