diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-03-09 12:50:05 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-03-09 12:50:05 +0000 |
commit | 3d9e535c30a2adf1ab01b3dd38f7f690e8ca8af4 (patch) | |
tree | c0bebf03135f1386c7df2c0b021473fd470e3902 | |
parent | beb5a38f955fcee098d298e7afde6c3aab040388 (diff) | |
download | mpfr-3d9e535c30a2adf1ab01b3dd38f7f690e8ca8af4.tar.gz |
[tests/{tset_si.c,tset_sj.c}] Fix when -DMPFR_USE_NO_MACRO is used.
The mpfr_get_exp() function checks that the argument is a regular
number, but the corresponding macro doesn't. The test code was
calling mpfr_get_exp() on 0, thus failed with MPFR_USE_NO_MACRO
defined. Here, the code was correct with the macro, because the
value was not used for the particular case 0.
This is fixed by testing 0 earlier (and doing a goto, but the code
has fewer tests and should be simpler to understand). Moreover,
mpfr_get_exp has been replaced by MPFR_GET_EXP, so that the argument
is checked with --enable-assert.
(merged changeset r14464 from the trunk)
git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/branches/4.1@14470 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | tests/tset_si.c | 14 | ||||
-rw-r--r-- | tests/tset_sj.c | 14 |
2 files changed, 16 insertions, 12 deletions
diff --git a/tests/tset_si.c b/tests/tset_si.c index df124e30e..56332d48b 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -127,27 +127,29 @@ test_2exp_extreme_aux (void) power of 2 is exact, unless underflow/overflow occurs. The tests on the exponent below avoid integer overflows (ep[i] may take extreme values). */ - e = mpfr_get_exp (x1); mpfr_clear_flags (); - if (j != 0 && ep[i] < __gmpfr_emin - e) /* underflow */ + if (j == 0) + goto zero; + e = MPFR_GET_EXP (x1); + if (ep[i] < __gmpfr_emin - e) /* underflow */ { mpfr_rnd_t r = (rnd == MPFR_RNDN && - (ep[i] < __gmpfr_emin - mpfr_get_exp (y) - 1 || + (ep[i] < __gmpfr_emin - MPFR_GET_EXP (y) - 1 || IS_POW2 (sign * j))) ? MPFR_RNDZ : (mpfr_rnd_t) rnd; inex1 = mpfr_underflow (x1, r, sign); flags1 = __gmpfr_flags; } - else if (j != 0 && ep[i] > __gmpfr_emax - e) /* overflow */ + else if (ep[i] > __gmpfr_emax - e) /* overflow */ { inex1 = mpfr_overflow (x1, (mpfr_rnd_t) rnd, sign); flags1 = __gmpfr_flags; } else { - if (j != 0) - mpfr_set_exp (x1, ep[i] + e); + mpfr_set_exp (x1, ep[i] + e); + zero: flags1 = inex1 != 0 ? MPFR_FLAGS_INEXACT : 0; } diff --git a/tests/tset_sj.c b/tests/tset_sj.c index 0c0e731dc..68ebe85b6 100644 --- a/tests/tset_sj.c +++ b/tests/tset_sj.c @@ -225,27 +225,29 @@ test_2exp_extreme_aux (void) power of 2 is exact, unless underflow/overflow occurs. The tests on the exponent below avoid integer overflows (ep[i] may take extreme values). */ - e = mpfr_get_exp (x1); mpfr_clear_flags (); - if (j != 0 && ep[i] < __gmpfr_emin - e) /* underflow */ + if (j == 0) + goto zero; + e = MPFR_GET_EXP (x1); + if (ep[i] < __gmpfr_emin - e) /* underflow */ { mpfr_rnd_t r = (rnd == MPFR_RNDN && - (ep[i] < __gmpfr_emin - mpfr_get_exp (y) - 1 || + (ep[i] < __gmpfr_emin - MPFR_GET_EXP (y) - 1 || IS_POW2 (sign * j))) ? MPFR_RNDZ : (mpfr_rnd_t) rnd; inex1 = mpfr_underflow (x1, r, sign); flags1 = __gmpfr_flags; } - else if (j != 0 && ep[i] > __gmpfr_emax - e) /* overflow */ + else if (ep[i] > __gmpfr_emax - e) /* overflow */ { inex1 = mpfr_overflow (x1, (mpfr_rnd_t) rnd, sign); flags1 = __gmpfr_flags; } else { - if (j != 0) - mpfr_set_exp (x1, ep[i] + e); + mpfr_set_exp (x1, ep[i] + e); + zero: flags1 = inex1 != 0 ? MPFR_FLAGS_INEXACT : 0; } } |