summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-06-26 07:28:10 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-06-26 07:28:10 +0000
commitfa563bc7f4e90c6a2801b70ba0e273c183cafb5c (patch)
treea0adfb5c4dc4f4772990537b94e76af302dc39bc
parent1e796e6f302686e3c13a8e6bf155dd5ba7e8b36c (diff)
downloadmpfr-fa563bc7f4e90c6a2801b70ba0e273c183cafb5c.tar.gz
[src/div_2ui.c] Fixed overflow case (can occur only when n = 0).
[tests/tmul_2exp.c] Completed the overflow test. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9595 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/div_2ui.c2
-rw-r--r--tests/tmul_2exp.c38
2 files changed, 34 insertions, 6 deletions
diff --git a/src/div_2ui.c b/src/div_2ui.c
index 12df43bb7..3aa8b6ae8 100644
--- a/src/div_2ui.c
+++ b/src/div_2ui.c
@@ -32,7 +32,7 @@ mpfr_div_2ui (mpfr_ptr y, mpfr_srcptr x, unsigned long n, mpfr_rnd_t rnd_mode)
rnd_mode),
("y[%Pu]=%.*Rg inexact=%d", mpfr_get_prec(y), mpfr_log_prec, y, inexact));
- if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
+ if (MPFR_UNLIKELY (n == 0 || MPFR_IS_SINGULAR (x)))
return mpfr_set (y, x, rnd_mode);
else
{
diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c
index abbc46915..1e4314b38 100644
--- a/tests/tmul_2exp.c
+++ b/tests/tmul_2exp.c
@@ -239,19 +239,19 @@ large0 (void)
large (MPFR_EMAX_MAX);
}
-/* Cases where mpfr_div_2ui overflows. */
+/* Cases where mpfr_div_2ui overflows when rounding is like away from zero. */
static void
div_overflow (mpfr_exp_t e)
{
mpfr_exp_t emax;
- mpfr_t x, y;
+ mpfr_t x, y1, y2;
int neg, r;
emax = mpfr_get_emax ();
set_emax (e);
mpfr_init2 (x, 8);
- mpfr_init2 (y, 6);
+ mpfr_inits2 (6, y1, y2, (mpfr_ptr) 0);
mpfr_set_inf (x, 1);
mpfr_nextbelow (x);
@@ -260,12 +260,40 @@ div_overflow (mpfr_exp_t e)
{
RND_LOOP (r)
{
- mpfr_div_2ui (y, x, 0, (mpfr_rnd_t) r);
+ int inex1, inex2;
+ mpfr_flags_t flags1, flags2;
+
+ /* Even if there isn't an overflow (rounding ~ toward zero),
+ the result is the same as the one of an overflow. */
+ inex1 = mpfr_overflow (y1, (mpfr_rnd_t) r, neg ? -1 : 1);
+ 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))
+ {
+ 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_neg (x, x, MPFR_RNDN);
}
- mpfr_clears (x, y, (mpfr_ptr) 0);
+ mpfr_clears (x, y1, y2, (mpfr_ptr) 0);
set_emax (emax);
}