diff options
-rw-r--r-- | doc/mpfr.texi | 12 | ||||
-rw-r--r-- | src/fits_intmax.c | 25 | ||||
-rw-r--r-- | src/fits_s.h | 15 | ||||
-rw-r--r-- | src/fits_u.h | 16 | ||||
-rw-r--r-- | src/zeta_ui.c | 6 | ||||
-rw-r--r-- | tests/tcoth.c | 3 | ||||
-rw-r--r-- | tests/texp.c | 3 | ||||
-rw-r--r-- | tests/tfits.c | 41 | ||||
-rw-r--r-- | tests/tfma.c | 3 | ||||
-rw-r--r-- | tests/tfms.c | 9 | ||||
-rw-r--r-- | tests/tgamma.c | 3 | ||||
-rw-r--r-- | tests/tgeneric.c | 14 | ||||
-rw-r--r-- | tests/tgeneric_ui.c | 4 | ||||
-rw-r--r-- | tests/tget_f.c | 17 | ||||
-rw-r--r-- | tests/tget_sj.c | 6 | ||||
-rw-r--r-- | tests/tgmpop.c | 10 | ||||
-rw-r--r-- | tests/tpow.c | 6 | ||||
-rw-r--r-- | tests/tpow3.c | 2 | ||||
-rw-r--r-- | tests/tpow_all.c | 15 | ||||
-rw-r--r-- | tests/trint.c | 6 | ||||
-rw-r--r-- | tests/troot.c | 2 | ||||
-rw-r--r-- | tests/tsech.c | 3 | ||||
-rw-r--r-- | tests/tset_si.c | 5 | ||||
-rw-r--r-- | tests/tsin_cos.c | 5 | ||||
-rw-r--r-- | tests/tsqr.c | 4 | ||||
-rw-r--r-- | tests/tstrtofr.c | 3 | ||||
-rw-r--r-- | tests/tsub.c | 3 | ||||
-rw-r--r-- | tests/tui_pow.c | 4 | ||||
-rw-r--r-- | tests/tzeta_ui.c | 6 |
29 files changed, 137 insertions, 114 deletions
diff --git a/doc/mpfr.texi b/doc/mpfr.texi index a641b01be..70e834e85 100644 --- a/doc/mpfr.texi +++ b/doc/mpfr.texi @@ -761,14 +761,16 @@ of The Art of Computer Programming (Section 4.2.2). The @code{MPFR_RNDF} mode works as follows: the computed value is either that corresponding to @code{MPFR_RNDD} or that corresponding to -@code{MPFR_RNDU}, except in the case where those values are identical, -in which case the two adjacent floating-point numbers can also be returned. +@code{MPFR_RNDU}. +In particular when those values are identical, +i.e., when the result of the corresponding operation is exactly +representable, that exact result is returned. In summary the error is always at most one unit-in-last-place of the computed -result, which can take two or three possible values. +result, which can take at most two possible values. For @code{MPFR_RNDF} the ternary value makes no sense, the inexact flag is undefined, the divide-by-zero flag is as with other roundings, and the underflow and overflow flags match what would be obtained -in the case the computed value would is @code{MPFR_RNDD} (resp. +in the case the computed value is the same as with @code{MPFR_RNDD} (resp. @code{MPFR_RNDU}). @anchor{ternary value}@cindex Ternary value @@ -1663,7 +1665,7 @@ that the corresponding conversion function (for example @code{mpfr_get_ui} for @code{mpfr_fits_ulong_p}), when called with faithful rounding, will always return a number that is representable in the corresponding type. As a consequence, for @code{MPFR_RNDF}, @code{mpfr_fits_ulong_p} will return -non-zero for a positive number less than @code{ULONG_MAX}. +non-zero for a non-negative number less or equal to @code{ULONG_MAX}. @end deftypefun @node Basic Arithmetic Functions, Comparison Functions, Conversion Functions, MPFR Interface diff --git a/src/fits_intmax.c b/src/fits_intmax.c index 4ea203149..923b4d7b4 100644 --- a/src/fits_intmax.c +++ b/src/fits_intmax.c @@ -41,14 +41,12 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) int res; if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f))) - /* Zero always fit, except for RNDF, since 0 might be rounded to -1 */ - return MPFR_IS_ZERO (f) ? (rnd != MPFR_RNDF) : 0; + /* Zero always fit */ + return MPFR_IS_ZERO (f) ? 1 : 0; /* now it fits if either (a) MINIMUM <= f <= MAXIMUM - (b) or MINIMUM <= round(f, prec(slong), rnd) <= MAXIMUM - except or rnd = RNDF: when f = MINIMUM or MAXIMUM, it might be - rounded to MINIMUM-1 or MAXIMUM+1 */ + (b) or MINIMUM <= round(f, prec(slong), rnd) <= MAXIMUM */ e = MPFR_EXP (f); if (e < 1) @@ -90,14 +88,15 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) /* hard case: first round to prec bits, then check */ saved_flags = __gmpfr_flags; mpfr_init2 (x, prec); - mpfr_set (x, f, rnd); + /* for RNDF, it is necessary and sufficient to check it fitst when rounding + away from zero */ + mpfr_set (x, f, (rnd == MPFR_RNDF) ? MPFR_RNDA : rnd); if (neg) { mpfr_init2 (y, prec); mpfr_set_sj (y, MPFR_INTMAX_MIN, MPFR_RNDN); - res = (rnd != MPFR_RNDF) ? mpfr_cmp (x, y) >= 0 - : mpfr_cmp (x, y) > 0; + res = mpfr_cmp (x, y) >= 0; mpfr_clear (y); } else @@ -107,15 +106,7 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) thus well-defined and different from e, in which case this means that the number does not fit. That's why we use MPFR_EXP, not MPFR_GET_EXP. */ - if (rnd != MPFR_RNDF) - res = MPFR_EXP (x) == e; - else - { - mpfr_init2 (y, prec); - mpfr_set_sj (y, MPFR_INTMAX_MAX, MPFR_RNDN); - res = mpfr_cmp (x, y) < 0; - mpfr_clear (y); - } + res = MPFR_EXP (x) == e; } mpfr_clear (x); diff --git a/src/fits_s.h b/src/fits_s.h index 5e87ae10b..a8ef15a41 100644 --- a/src/fits_s.h +++ b/src/fits_s.h @@ -37,14 +37,12 @@ FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) int res; if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f))) - /* Zero always fit, except for RNDF, since 0 might be rounded to -1 */ - return MPFR_IS_ZERO (f) ? (rnd != MPFR_RNDF) : 0; + /* Zero always fit */ + return MPFR_IS_ZERO (f) ? 1 : 0; /* now it fits if either (a) MINIMUM <= f <= MAXIMUM - (b) or MINIMUM <= round(f, prec(slong), rnd) <= MAXIMUM - except or rnd = RNDF: when f = MINIMUM or MAXIMUM, it might be - rounded to MINIMUM-1 or MAXIMUM+1 */ + (b) or MINIMUM <= round(f, prec(slong), rnd) <= MAXIMUM */ e = MPFR_GET_EXP (f); if (e < 1) @@ -86,17 +84,14 @@ FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) /* hard case: first round to prec bits, then check */ saved_flags = __gmpfr_flags; mpfr_init2 (x, prec); - mpfr_set (x, f, rnd); + /* for RNDF, it suffices to check it fits when rounded away from zero */ + mpfr_set (x, f, (rnd == MPFR_RNDF) ? MPFR_RNDA : rnd); /* Warning! Due to the rounding, x can be an infinity. Here we use the fact that singular numbers have a special exponent field, thus well-defined and different from e, in which case this means that the number does not fit. That's why we use MPFR_EXP, not MPFR_GET_EXP. */ res = neg ? (mpfr_cmp_si (x, MINIMUM) >= 0) : (MPFR_EXP (x) == e); - /* special case for RNDF and x = MINIMUM or MAXIMUM */ - if (MPFR_UNLIKELY(rnd == MPFR_RNDF && (mpfr_cmp_si (x, MINIMUM) == 0 || - mpfr_cmp_si (x, MAXIMUM) == 0))) - res = 0; mpfr_clear (x); __gmpfr_flags = saved_flags; return res; diff --git a/src/fits_u.h b/src/fits_u.h index df0c2e3f6..45c25f82d 100644 --- a/src/fits_u.h +++ b/src/fits_u.h @@ -33,8 +33,7 @@ FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) int res; if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f))) - /* Zero always fits except for RNDF, since 0 might be rounded to -1 */ - return MPFR_IS_ZERO (f) ? (rnd != MPFR_RNDF) : 0; + return MPFR_IS_ZERO (f) ? 1 : 0; /* Zero always fits */ e = MPFR_GET_EXP (f); @@ -42,15 +41,11 @@ FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) return e >= 1 ? 0 /* f <= -1 does not fit */ : rnd != MPFR_RNDN ? MPFR_IS_LIKE_RNDU (rnd, -1) /* directed mode */ : e < 0 ? 1 /* f > -1/2 fits in MPFR_RNDN */ - : (rnd != MPFR_RNDF) - ? mpfr_powerof2_raw(f) /* -1/2 fits, -1 < f < -1/2 don't */ - : 0; /* a negative number can be rounded to -1 for RNDF */ + : mpfr_powerof2_raw(f); /* -1/2 fits, -1 < f < -1/2 don't */ - /* Now it fits if either + /* Now it fits if (a) f <= MAXIMUM - (b) round(f, prec(slong), rnd) <= MAXIMUM - except when f = MAXIMUM and rnd = RNDF, where it might be rounded to - MAXIMUM+1 */ + (b) round(f, prec(slong), rnd) <= MAXIMUM */ /* first compute prec(MAXIMUM); fits in an int */ for (s = MAXIMUM, prec = 0; s != 0; s /= 2, prec ++); @@ -70,6 +65,7 @@ FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) /* hard case: first round to prec bits, then check */ saved_flags = __gmpfr_flags; mpfr_init2 (x, prec); + /* For MPFR_RNDF, if f > 0 fits with RNDU, it will also fit with RNDD. */ mpfr_set (x, f, (rnd != MPFR_RNDF) ? rnd : MPFR_RNDU); /* Warning! Due to the rounding, x can be an infinity. Here we use the fact that singular numbers have a special exponent field, @@ -77,8 +73,6 @@ FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) that the number does not fit. That's why we use MPFR_EXP, not MPFR_GET_EXP. */ res = MPFR_EXP (x) == e; - if (MPFR_UNLIKELY(rnd == MPFR_RNDF && mpfr_cmp_ui (x, MAXIMUM) == 0)) - res = 0; mpfr_clear (x); __gmpfr_flags = saved_flags; return res; diff --git a/src/zeta_ui.c b/src/zeta_ui.c index 6d43504ef..5031f0588 100644 --- a/src/zeta_ui.c +++ b/src/zeta_ui.c @@ -32,10 +32,8 @@ mpfr_zeta_ui (mpfr_ptr z, unsigned long m, mpfr_rnd_t r) (("m=%lu rnd=%d prec=%Pu", m, r, mpfr_get_prec (z)), ("z[%Pu]=%.*Rg", mpfr_get_prec (z), mpfr_log_prec, z)); - if (m == 0) - { - return mpfr_set_si_2exp (z, -1, -1, r); - } + if (m == 0) /* zeta(0) = -1/2 */ + return mpfr_set_si_2exp (z, -1, -1, r); else if (m == 1) { MPFR_SET_INF (z); diff --git a/tests/tcoth.c b/tests/tcoth.c index 6a7b22d1c..7a2782234 100644 --- a/tests/tcoth.c +++ b/tests/tcoth.c @@ -143,6 +143,9 @@ underflowed_cothinf (void) for (i = -1; i <= 1; i += 2) RND_LOOP (rnd) { + if (rnd == MPFR_RNDF) + continue; /* this test does not make sense, since RNDF does not + give deterministic results */ mpfr_set_inf (x, i); mpfr_clear_flags (); set_emin (2); /* 1 is not representable. */ diff --git a/tests/texp.c b/tests/texp.c index d03b9fb40..a202feedf 100644 --- a/tests/texp.c +++ b/tests/texp.c @@ -866,6 +866,9 @@ underflow_up (int extended_emin) (unsigned int) __gmpfr_flags, flags); err = 1; } + if (rnd == MPFR_RNDF) + continue; /* the test below makes no sense, since RNDF + does not give a deterministic result */ if (rnd == MPFR_RNDU || rnd == MPFR_RNDA || rnd == MPFR_RNDN ? mpfr_cmp0 (y, minpos) != 0 : MPFR_NOTZERO (y)) { diff --git a/tests/tfits.c b/tests/tfits.c index b91de17f2..3e2666740 100644 --- a/tests/tfits.c +++ b/tests/tfits.c @@ -101,14 +101,13 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., do \ { \ SET (x, V, MPFR_RNDN); \ - FTEST (N, (r != MPFR_RNDF) ^ !!, FCT); \ + FTEST (N, !, FCT); \ mpfr_set_si_2exp (y, (V) < 0 ? -1 : 1, -2, MPFR_RNDN); \ mpfr_add (x, x, y, MPFR_RNDN); \ FTEST (N+1, (r == MPFR_RNDN || \ MPFR_IS_LIKE_RNDZ (r, (V) < 0)) ^ !!, FCT); \ mpfr_add (x, x, y, MPFR_RNDN); \ mpfr_add (x, x, y, MPFR_RNDN); \ - if (r != MPFR_RNDF) \ FTEST (N+3, MPFR_IS_LIKE_RNDZ (r, (V) < 0) ^ !!, FCT); \ mpfr_add (x, x, y, MPFR_RNDN); \ FTEST (N+4, !!, FCT); \ @@ -150,17 +149,11 @@ main (void) /* Check +0 */ mpfr_set_zero (x, 1); - if (r != MPFR_RNDF) - CHECK_ALL (4, !); - else - CHECK_ALL (4, !!); /* +0 does not fit for RNDF */ + CHECK_ALL (4, !); /* Check -0 */ mpfr_set_zero (x, -1); - if (r != MPFR_RNDF) - CHECK_ALL (5, !); - else - CHECK_ALL (5, !!); + CHECK_ALL (5, !); /* Check small positive op */ mpfr_set_str1 (x, "1@-1"); @@ -198,22 +191,14 @@ main (void) int inv; mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN); - mpfr_rint (y, x, (mpfr_rnd_t) r); + /* for RNDF, it fits if it fits when rounding away from zero */ + mpfr_rint (y, x, (mpfr_rnd_t) (r != MPFR_RNDF) ? r : MPFR_RNDA); inv = MPFR_NOTZERO (y); - if (r != MPFR_RNDF) - FTEST (80, inv ^ !, mpfr_fits_ulong_p); - else - FTEST (80, !!, mpfr_fits_ulong_p); + FTEST (80, inv ^ !, mpfr_fits_ulong_p); FTEST (81, !, mpfr_fits_slong_p); - if (r != MPFR_RNDF) - FTEST (82, inv ^ !, mpfr_fits_uint_p); - else - FTEST (82, !!, mpfr_fits_uint_p); + FTEST (82, inv ^ !, mpfr_fits_uint_p); FTEST (83, !, mpfr_fits_sint_p); - if (r != MPFR_RNDF) - FTEST (84, inv ^ !, mpfr_fits_ushort_p); - else - FTEST (84, !!, mpfr_fits_ushort_p); + FTEST (84, inv ^ !, mpfr_fits_ushort_p); FTEST (85, !, mpfr_fits_sshort_p); } } @@ -238,17 +223,11 @@ main (void) /* Check +0 */ mpfr_set_zero (x, 1); - if (r != MPFR_RNDF) - CHECK_MAX (4, !); - else - CHECK_MAX (4, !!); /* +0 does not fit for RNDF */ + CHECK_MAX (4, !); /* Check -0 */ mpfr_set_zero (x, -1); - if (r != MPFR_RNDF) - CHECK_MAX (5, !); - else - CHECK_MAX (5, !!); + CHECK_MAX (5, !); /* Check small positive op */ mpfr_set_str1 (x, "1@-1"); diff --git a/tests/tfma.c b/tests/tfma.c index f2807c019..dcd6e0654 100644 --- a/tests/tfma.c +++ b/tests/tfma.c @@ -128,6 +128,9 @@ test_overflow2 (void) { int inf, overflow; + if (rnd == MPFR_RNDF) + continue; + inf = rnd == MPFR_RNDN || rnd == MPFR_RNDD || rnd == MPFR_RNDA; overflow = inf || i <= 0; diff --git a/tests/tfms.c b/tests/tfms.c index 8a832accc..07054e37e 100644 --- a/tests/tfms.c +++ b/tests/tfms.c @@ -46,8 +46,10 @@ test_exact (void) mpfr_mul (r1, a, b, (mpfr_rnd_t) rnd) || mpfr_sub (r1, r1, c, (mpfr_rnd_t) rnd)) { - printf ("test_exact internal error for (%d,%d,%d,%d)\n", - i, j, k, rnd); + if (rnd == MPFR_RNDF) + break; + printf ("test_exact internal error for (%d,%d,%d,%d,%s)\n", + i, j, k, rnd, mpfr_print_rnd_mode (rnd)); exit (1); } if (mpfr_fms (r2, a, b, c, (mpfr_rnd_t) rnd)) @@ -128,6 +130,9 @@ test_overflow2 (void) { int inf, overflow; + if (rnd == MPFR_RNDF) + continue; + inf = rnd == MPFR_RNDN || rnd == MPFR_RNDD || rnd == MPFR_RNDA; overflow = inf || i <= 0; diff --git a/tests/tgamma.c b/tests/tgamma.c index 2b4555964..84e2876ba 100644 --- a/tests/tgamma.c +++ b/tests/tgamma.c @@ -802,6 +802,9 @@ tiny_aux (int stop, mpfr_exp_t e) mpfr_rnd_t rr = (mpfr_rnd_t) r; mpfr_exp_t exponent, emax; + if (rr == MPFR_RNDF) + continue; + /* Exponent of the rounded value in unbounded exponent range. */ exponent = expected_dir[s][r] < 0 && s == 0 ? - e : 1 - e; diff --git a/tests/tgeneric.c b/tests/tgeneric.c index 5e3a34f47..0cd14248d 100644 --- a/tests/tgeneric.c +++ b/tests/tgeneric.c @@ -355,7 +355,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) ctrt++; /* If rnd = RNDF, check that we obtain the same result as - RNDD or RNDU, except when RNDD and RNDU are exact */ + RNDD or RNDU. */ if (rnd == MPFR_RNDF) { int ok; @@ -386,12 +386,6 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) TEST_FUNCTION (yu, x, MPFR_RNDU); #endif ok = EQUAL (y, yd) || EQUAL (y, yu); - if (compare == 0 && ok == 0) - { - mpfr_nextbelow (yd); - mpfr_nextabove (yu); - ok = EQUAL (y, yd) || EQUAL (y, yu); - } if (ok == 0) { printf ("For RNDF, result does not match RNDD nor RNDU\n"); @@ -464,7 +458,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) flags = __gmpfr_flags; mpfr_set_emax (oemax); ex_flags = MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT; - /* for RNDF, this test makes no sense, since RNDF + /* For RNDF, this test makes no sense, since RNDF might return either the maximal floating-point value or infinity, and the flags might differ in those two cases. */ @@ -518,7 +512,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) flags = __gmpfr_flags; mpfr_set_emin (oemin); ex_flags = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT; - /* for RNDF, this test makes no sense, since RNDF + /* For RNDF, this test makes no sense, since RNDF might return either the maximal floating-point value or infinity, and the flags might differ in those two cases. */ @@ -587,7 +581,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) flags = __gmpfr_flags; mpfr_set_emin (oemin); mpfr_set_emax (oemax); - /* that test makes no sense for RNDF */ + /* That test makes no sense for RNDF. */ if (rnd != MPFR_RNDF && ! (SAME_VAL (w, y) && SAME_SIGN (inexact, compare) && flags == oldflags)) diff --git a/tests/tgeneric_ui.c b/tests/tgeneric_ui.c index 94658787d..b7c53a97e 100644 --- a/tests/tgeneric_ui.c +++ b/tests/tgeneric_ui.c @@ -74,7 +74,7 @@ test_generic_ui (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int N) else /* unsigned */ u = n == 2 ? 0 : -1; } - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); mpfr_set_prec (y, yprec); compare = TEST_FUNCTION (y, x, u, rnd); if (mpfr_can_round (y, yprec, rnd, rnd, prec)) @@ -109,7 +109,7 @@ test_generic_ui (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int N) compare = compare + compare2; else compare = inexact; /* cannot determine sign(t-f(x)) */ - if (! SAME_SIGN (inexact, compare)) + if (! SAME_SIGN (inexact, compare) && rnd != MPFR_RNDF) { printf ("Wrong inexact flag for rnd=%s: expected %d, got %d" "\n", mpfr_print_rnd_mode (rnd), compare, inexact); diff --git a/tests/tget_f.c b/tests/tget_f.c index a1eef4443..b0af066c6 100644 --- a/tests/tget_f.c +++ b/tests/tget_f.c @@ -189,9 +189,12 @@ ternary_test (void) { inex = mpfr_get_f (x, y, (mpfr_rnd_t) rnd); - if (inex != 0 || mpfr_cmp_f (y, x) !=0) + if (rnd == MPFR_RNDF) + continue; + + if (inex != 0 || mpfr_cmp_f (y, x) != 0) { - printf ("Error in mpfr_get_f (x, y, %s)\nx = ", + printf ("Error (1) in mpfr_get_f (x, y, %s)\nx = ", mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); mpf_out_str (stdout, 2, 0, x); printf ("\ny = "); @@ -220,10 +223,13 @@ ternary_test (void) inex = mpfr_get_f (x, y, (mpfr_rnd_t) rnd); + if (rnd == MPFR_RNDF) + continue; + if (! SAME_SIGN (expected_inex, inex) || SAME_SIGN (expected_inex, mpfr_cmp_f (y, x))) { - printf ("Error in mpfr_get_f (x, y, %s)\nx = ", + printf ("Error (2) in mpfr_get_f (x, y, %s)\nx = ", mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); mpf_out_str (stdout, 2, 0, x); printf ("\ny = "); @@ -243,9 +249,12 @@ ternary_test (void) { inex = mpfr_get_f (x, y, (mpfr_rnd_t) rnd); + if (rnd == MPFR_RNDF) + continue; + if (! SAME_SIGN (inex, -mpfr_cmp_f (y, x))) { - printf ("Error in mpfr_get_f (x, y, %s)\nx = ", + printf ("Error (3) in mpfr_get_f (x, y, %s)\nx = ", mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); mpf_out_str (stdout, 2, 0, x); printf ("\ny = "); diff --git a/tests/tget_sj.c b/tests/tget_sj.c index 06d8024d9..9548d2787 100644 --- a/tests/tget_sj.c +++ b/tests/tget_sj.c @@ -85,7 +85,7 @@ check_sj (intmax_t s, mpfr_ptr x) ex_flags |= MPFR_FLAGS_INEXACT; r = mpfr_get_sj (y, (mpfr_rnd_t) rnd); gt_flags = __gmpfr_flags; - if (r != s || gt_flags != ex_flags) + if ((r != s || gt_flags != ex_flags) && rnd != MPFR_RNDF) { printf ("Error in check_sj for fi = %d, y = ", fi); mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN); @@ -144,7 +144,7 @@ check_uj (uintmax_t u, mpfr_ptr x) ex_flags |= MPFR_FLAGS_INEXACT; r = mpfr_get_uj (y, (mpfr_rnd_t) rnd); gt_flags = __gmpfr_flags; - if (r != u || gt_flags != ex_flags) + if ((r != u || gt_flags != ex_flags) && rnd != MPFR_RNDF) { printf ("Error in check_uj for fi = %d, y = ", fi); mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN); @@ -249,7 +249,7 @@ test_get_uj_smallneg (void) uintmax_t u; mpfr_clear_erangeflag (); - s = mpfr_get_sj (x, (mpfr_rnd_t) r); + s = mpfr_get_sj (x, (mpfr_rnd_t) (r != MPFR_RNDF) ? r : MPFR_RNDA); if (mpfr_erangeflag_p ()) { printf ("ERROR for get_sj + ERANGE + small negative op" diff --git a/tests/tgmpop.c b/tests/tgmpop.c index 688d2bf85..4110b8a7b 100644 --- a/tests/tgmpop.c +++ b/tests/tgmpop.c @@ -571,13 +571,13 @@ test_genericz (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int N, { mpfr_urandomb (arg1, RANDS); mpz_urandomb (arg2, RANDS, 1024); - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); mpfr_set_prec (dst_big, 2*prec); - compare = func(dst_big, arg1, arg2, rnd); + compare = func (dst_big, arg1, arg2, rnd); if (mpfr_can_round (dst_big, 2*prec, rnd, rnd, prec)) { mpfr_set (tmp, dst_big, rnd); - inexact = func(dst_small, arg1, arg2, rnd); + inexact = func (dst_small, arg1, arg2, rnd); if (mpfr_cmp (tmp, dst_small)) { printf ("Results differ for prec=%u rnd_mode=%s and %s_z:\n" @@ -648,7 +648,7 @@ test_generic2z (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int N, { mpfr_urandomb (arg1, RANDS); mpz_urandomb (arg2, RANDS, 1024); - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); mpfr_set_prec (dst_big, 2*prec); compare = func(dst_big, arg2, arg1, rnd); if (mpfr_can_round (dst_big, 2*prec, rnd, rnd, prec)) @@ -726,7 +726,7 @@ test_genericq (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int N, mpfr_urandomb (arg1, RANDS); mpq_set_ui (arg2, randlimb (), randlimb() ); mpq_canonicalize (arg2); - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); mpfr_set_prec (dst_big, prec+10); compare = func(dst_big, arg1, arg2, rnd); if (mpfr_can_round (dst_big, prec+10, rnd, rnd, prec)) diff --git a/tests/tpow.c b/tests/tpow.c index 3bcf7a9a7..1c816392b 100644 --- a/tests/tpow.c +++ b/tests/tpow.c @@ -438,7 +438,7 @@ check_inexact (mpfr_prec_t p) mpfr_urandomb (x, RANDS); u = randlimb () % 2; for (q = MPFR_PREC_MIN; q <= p; q++) - for (rnd = 0; rnd < MPFR_RND_MAX; rnd++) + RND_LOOP(rnd) { mpfr_set_prec (y, q); mpfr_set_prec (z, q + 10); @@ -1485,6 +1485,10 @@ bug20080721 (void) inex0 = i ? -1 : 1; mpfr_clear_flags (); inex = mpfr_pow (z, x, y, (mpfr_rnd_t) rnd); + + if (rnd == MPFR_RNDF) + continue; + if (__gmpfr_flags != MPFR_FLAGS_INEXACT || ! SAME_SIGN (inex, inex0) || MPFR_IS_NAN (z) || mpfr_cmp (z, t[i]) != 0) { diff --git a/tests/tpow3.c b/tests/tpow3.c index 2b981bf54..eace4058c 100644 --- a/tests/tpow3.c +++ b/tests/tpow3.c @@ -61,7 +61,7 @@ main (int argc, char *argv[]) mpfr_urandomb (s, RANDS); if (randlimb () % 2) mpfr_neg (s, s, MPFR_RNDN); - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); mpfr_set_prec (y, yprec); compare = mpfr_pow (y, x, s, rnd); err = (rnd == MPFR_RNDN) ? yprec + 1 : yprec; diff --git a/tests/tpow_all.c b/tests/tpow_all.c index 7f57e2a9e..2855d2cb2 100644 --- a/tests/tpow_all.c +++ b/tests/tpow_all.c @@ -373,6 +373,9 @@ tst (void) int exact, inex; unsigned int flags; + if (rnd == MPFR_RNDF) + continue; + if (my_setstr (x, val[i]) || my_setstr (y, val[j])) { printf ("internal error for (%d,%d,%d)\n", i, j, rnd); @@ -512,6 +515,9 @@ underflow_up1 (void) { int zero; + if (rnd == MPFR_RNDF) + continue; + zero = (i > 4 && (rnd == MPFR_RNDZ || rnd == MPFR_RNDD)) || (i >= 8 && rnd == MPFR_RNDN); @@ -582,6 +588,9 @@ underflow_up2 (void) int expected_inex; char sy[256]; + if (rnd == MPFR_RNDF) + continue; + mpfr_set_ui (z0, 0, MPFR_RNDN); expected_inex = rnd == MPFR_RNDN || rnd == MPFR_RNDU || rnd == MPFR_RNDA ? (mpfr_nextabove (z0), 1) : -1; @@ -619,6 +628,9 @@ underflow_up3 (void) unsigned int ufinex = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT; int expected_inex; + if (rnd == MPFR_RNDF) + continue; + mpfr_set_ui (x, 2, MPFR_RNDN); if (i < 0) mpfr_nextbelow (x); @@ -695,6 +707,9 @@ overflow_inv (void) int inf, overflow; mpfr_rnd_t rnd2; + if (rnd == MPFR_RNDF) + continue; + if (rnd == MPFR_RNDA) rnd2 = s < 0 ? MPFR_RNDD : MPFR_RNDU; else diff --git a/tests/trint.c b/tests/trint.c index e7986ca88..6aec8f20c 100644 --- a/tests/trint.c +++ b/tests/trint.c @@ -171,8 +171,8 @@ special (void) inex2 = mpfr_rint_##F (z, x, (mpfr_rnd_t) r); \ flags = __gmpfr_flags; \ if (! (mpfr_equal_p (y, z) && \ - (r == MPFR_RNDF || (SAME_SIGN (inex1, inex2) && \ - flags == ex_flags)))) \ + SAME_SIGN (inex1, inex2) && \ + flags == ex_flags)) \ { \ printf ("Basic test failed on mpfr_rint_" #F \ ", prec = %d, i = %d, %s\n", prec, s * i, \ @@ -287,6 +287,8 @@ basic_tests (void) e = mpfr_get_exp (x); RND_LOOP(r) { + if (r == MPFR_RNDF) + continue; BASIC_TEST (trunc, s * (i/4)); BASIC_TEST (floor, s > 0 ? i/4 : - ((i+3)/4)); BASIC_TEST (ceil, s > 0 ? (i+3)/4 : - (i/4)); diff --git a/tests/troot.c b/tests/troot.c index 291056d38..c70816241 100644 --- a/tests/troot.c +++ b/tests/troot.c @@ -380,7 +380,7 @@ cmp_pow (void) int inex1, inex2; tests_default_random (x, 0, __gmpfr_emin, __gmpfr_emax, 1); - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); mpfr_set_ui_2exp (y1, 1, -h, MPFR_RNDN); mpfr_clear_flags (); inex1 = mpfr_pow (y1, x, y1, rnd); diff --git a/tests/tsech.c b/tests/tsech.c index af001f7fc..9f5006ddb 100644 --- a/tests/tsech.c +++ b/tests/tsech.c @@ -116,6 +116,9 @@ overflowed_sech0 (void) for (i = -1; i <= 1; i++) RND_LOOP (rnd) { + if (rnd == MPFR_RNDF) + continue; + mpfr_set_si_2exp (x, i, -512 * ABS (i), MPFR_RNDN); mpfr_clear_flags (); inex = mpfr_sech (x, x, (mpfr_rnd_t) rnd); diff --git a/tests/tset_si.c b/tests/tset_si.c index 501f3bff7..0abeed540 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -158,7 +158,7 @@ test_get_ui_smallneg (void) unsigned long u; mpfr_clear_erangeflag (); - s = mpfr_get_si (x, (mpfr_rnd_t) r); + s = mpfr_get_si (x, (mpfr_rnd_t) (r != MPFR_RNDF) ? r : MPFR_RNDA); if (mpfr_erangeflag_p ()) { printf ("ERROR for get_si + ERANGE + small negative op" @@ -225,6 +225,9 @@ static void get_tests (void) mpfr_flags_t ex_flags, flags; int k, overflow; + if (r == MPFR_RNDF) + continue; + k = (j + 8 + (MPFR_IS_LIKE_RNDD (r, MPFR_SIGN (x)) ? 0 : MPFR_IS_LIKE_RNDU (r, MPFR_SIGN (x)) ? 3 : diff --git a/tests/tsin_cos.c b/tests/tsin_cos.c index 74bbbb56e..07cef1dbf 100644 --- a/tests/tsin_cos.c +++ b/tests/tsin_cos.c @@ -579,6 +579,8 @@ consistency (void) mpfr_set_si (x, (j & 2) ? 1 : -1, MPFR_RNDN); mpfr_set_exp (x, mpfr_get_emin ()); rnd = (mpfr_rnd_t) (i % MPFR_RND_MAX); + if (rnd == MPFR_RNDF) + goto end; flags_before = 0; if (j & 4) mpfr_set_emax (-17); @@ -586,7 +588,7 @@ consistency (void) else { tests_default_random (x, 256, -5, 50, 0); - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); flags_before = (randlimb () & 1) ? (unsigned int) (MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE) : (unsigned int) 0; @@ -626,6 +628,7 @@ consistency (void) flags_sin, flags_cos, flags, flags_ref); exit (1); } + end: mpfr_clears (x, s1, s2, c1, c2, (mpfr_ptr) 0); mpfr_set_emin (emin); mpfr_set_emax (emax); diff --git a/tests/tsqr.c b/tests/tsqr.c index ec585d9ce..1771ee206 100644 --- a/tests/tsqr.c +++ b/tests/tsqr.c @@ -67,8 +67,10 @@ check_random (mpfr_prec_t p) { mpfr_urandomb (x, RANDS); if (MPFR_IS_PURE_FP(x)) - for (r = 0 ; r < MPFR_RND_MAX ; r++) + RND_LOOP(r) { + if (r == MPFR_RNDF) + continue; inexact1 = mpfr_mul (y, x, x, (mpfr_rnd_t) r); inexact2 = mpfr_sqr (z, x, (mpfr_rnd_t) r); if (mpfr_cmp (y, z)) diff --git a/tests/tstrtofr.c b/tests/tstrtofr.c index ede1f3d14..0d416be70 100644 --- a/tests/tstrtofr.c +++ b/tests/tstrtofr.c @@ -1161,6 +1161,9 @@ bug20120829 (void) { mpfr_rnd_t rnd = (mpfr_rnd_t) r; + if (r == MPFR_RNDF) + continue; + inex1 = mpfr_exp10 (x1, e, rnd); inex1 = SIGN (inex1); inex2 = mpfr_strtofr (x2, s, NULL, 0, rnd); diff --git a/tests/tsub.c b/tests/tsub.c index b0a16e006..8252a563c 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -690,6 +690,9 @@ check_max_almosteven (void) mpfr_flags_t flags1, flags2; int inex1, inex2; + if (rnd == MPFR_RNDF) + continue; + /* Expected result. */ flags1 = MPFR_FLAGS_INEXACT; if (rnd == MPFR_RNDN || MPFR_IS_LIKE_RNDZ (rnd, neg)) diff --git a/tests/tui_pow.c b/tests/tui_pow.c index feb844b5b..2a6acab74 100644 --- a/tests/tui_pow.c +++ b/tests/tui_pow.c @@ -239,12 +239,12 @@ main (int argc, char *argv[]) for (prec = p0; prec <= p1; prec++) { mpfr_set_prec (x, prec); - for (n=0; n<N; n++) + for (n = 0; n < N; n++) { int nt; nt = randlimb () & INT_MAX; mpfr_urandomb (x, RANDS); - rnd = RND_RAND (); + do rnd = RND_RAND (); while (rnd == MPFR_RNDF); check1 (x, prec, nt, rnd); } } diff --git a/tests/tzeta_ui.c b/tests/tzeta_ui.c index 868c8756e..07fd7acd4 100644 --- a/tests/tzeta_ui.c +++ b/tests/tzeta_ui.c @@ -78,6 +78,9 @@ main (int argc, char *argv[]) { int ex_inex; + if (rnd == MPFR_RNDF) + continue; + set_emin (i); set_emax (i); mpfr_clear_flags (); @@ -152,6 +155,9 @@ main (int argc, char *argv[]) for (n = 0; n < 50; n++) RND_LOOP (rnd) { + if (rnd == MPFR_RNDF) + continue; + mpfr_zeta_ui (y, n, MPFR_RNDN); if (mpfr_can_round (y, yprec, MPFR_RNDN, MPFR_RNDZ, prec + (rnd == MPFR_RNDN))) |