diff options
-rw-r--r-- | src/div_2si.c | 2 | ||||
-rw-r--r-- | tests/tmul_2exp.c | 47 |
2 files changed, 28 insertions, 21 deletions
diff --git a/src/div_2si.c b/src/div_2si.c index a6a1694a8..4220bcfae 100644 --- a/src/div_2si.c +++ b/src/div_2si.c @@ -49,7 +49,7 @@ mpfr_div_2si (mpfr_ptr y, mpfr_srcptr x, long int n, mpfr_rnd_t rnd_mode) rnd_mode = MPFR_RNDZ; return mpfr_underflow (y, rnd_mode, MPFR_SIGN(y)); } - else if (MPFR_UNLIKELY(n < 0 && (__gmpfr_emax < MPFR_EMIN_MIN - n || + else if (MPFR_UNLIKELY(n <= 0 && (__gmpfr_emax < MPFR_EMIN_MIN - n || exp > __gmpfr_emax + n)) ) return mpfr_overflow (y, rnd_mode, MPFR_SIGN(y)); diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c index 1e4314b38..e11d5d5cf 100644 --- a/tests/tmul_2exp.c +++ b/tests/tmul_2exp.c @@ -239,13 +239,14 @@ large0 (void) large (MPFR_EMAX_MAX); } -/* Cases where mpfr_div_2ui overflows when rounding is like away from zero. */ +/* Cases where mpfr_div_2ui and mpfr_div_2si overflow when rounding + is like away from zero. */ static void div_overflow (mpfr_exp_t e) { mpfr_exp_t emax; mpfr_t x, y1, y2; - int neg, r; + int neg, r, si; emax = mpfr_get_emax (); set_emax (e); @@ -269,25 +270,31 @@ div_overflow (mpfr_exp_t e) flags1 = MPFR_FLAGS_INEXACT; if (mpfr_inf_p (y1)) flags1 |= MPFR_FLAGS_OVERFLOW; - mpfr_clear_flags (); - inex2 = mpfr_div_2ui (y2, x, 0, (mpfr_rnd_t) r); - flags2 = __gmpfr_flags; - if (!(mpfr_equal_p (y1, y2) && - SAME_SIGN (inex1, inex2) && - flags1 == flags2)) + for (si = 0; si <= 1; si++) { - printf ("Error in div_overflow for %s, x = ", - mpfr_print_rnd_mode ((mpfr_rnd_t) r)); - mpfr_dump (x); - printf ("Expected "); - mpfr_dump (y1); - printf (" with inex = %d, flags =", inex1); - flags_out (flags1); - printf ("Got "); - mpfr_dump (y2); - printf (" with inex = %d, flags =", inex2); - flags_out (flags2); - exit (1); + mpfr_clear_flags (); + inex2 = si ? + mpfr_div_2si (y2, x, 0, (mpfr_rnd_t) r) : + mpfr_div_2ui (y2, x, 0, (mpfr_rnd_t) r); + flags2 = __gmpfr_flags; + if (!(mpfr_equal_p (y1, y2) && + SAME_SIGN (inex1, inex2) && + flags1 == flags2)) + { + printf ("Error in div_overflow for %s, mpfr_div_2%s, x = ", + mpfr_print_rnd_mode ((mpfr_rnd_t) r), + si ? "si" : "ui"); + mpfr_dump (x); + printf ("Expected "); + mpfr_dump (y1); + printf (" with inex = %d, flags =", inex1); + flags_out (flags1); + printf ("Got "); + mpfr_dump (y2); + printf (" with inex = %d, flags =", inex2); + flags_out (flags2); + exit (1); + } } } mpfr_neg (x, x, MPFR_RNDN); |