summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-04-08 15:11:29 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-04-08 15:11:29 +0000
commitf964bbd48c0373a6a41e110575669a5df79eb72d (patch)
treed9e74c32343f3b3a55a80243f7f15d6ce795bb82
parent0182ca2fff4ca8fc2634c3fcc425c745cb9a49ed (diff)
downloadmpfr-f964bbd48c0373a6a41e110575669a5df79eb72d.tar.gz
[tests/tsum.c] Added check_overflow test, which triggers a bug.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/new-sum@9361 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--tests/tsum.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/tsum.c b/tests/tsum.c
index 2687be319..963a0bdc8 100644
--- a/tests/tsum.c
+++ b/tests/tsum.c
@@ -851,6 +851,57 @@ cancel (void)
mpfr_clear (bound);
}
+#define NOVFL 30
+
+static void
+check_overflow (void)
+{
+ mpfr_t sum1, sum2, x, y;
+ mpfr_ptr t[2 * NOVFL];
+ mpfr_exp_t emin, emax;
+ int i, r;
+
+ emin = mpfr_get_emin ();
+ emax = mpfr_get_emax ();
+ set_emin (MPFR_EMIN_MIN);
+ set_emax (MPFR_EMAX_MAX);
+
+ mpfr_inits2 (32, sum1, sum2, x, y, (mpfr_ptr) 0);
+ mpfr_setmax (x, mpfr_get_emax ());
+ mpfr_neg (y, x, MPFR_RNDN);
+
+ for (i = 0; i < 2 * NOVFL; i++)
+ t[i] = i < NOVFL ? x : y;
+
+ for (i = 1; i <= 2; i++)
+ RND_LOOP(r)
+ {
+ int inex1, inex2;
+
+ inex1 = mpfr_add (sum1, x, i == 1 ? x : y, (mpfr_rnd_t) r);
+ inex2 = mpfr_sum (sum2, t, i * NOVFL, (mpfr_rnd_t) r);
+ MPFR_ASSERTN (mpfr_check (sum1));
+ MPFR_ASSERTN (mpfr_check (sum2));
+ if (!(mpfr_equal_p (sum1, sum2) && SAME_SIGN (inex1, inex2)))
+ {
+ printf ("Error in check_overflow on %s, i = %d\n",
+ mpfr_print_rnd_mode ((mpfr_rnd_t) r), i);
+ printf ("Expected ");
+ mpfr_dump (sum1);
+ printf ("with inex = %d\n", inex1);
+ printf ("Got ");
+ mpfr_dump (sum2);
+ printf ("with inex = %d\n", inex2);
+ exit (1);
+ }
+ }
+
+ mpfr_clears (sum1, sum2, x, y, (mpfr_ptr) 0);
+
+ set_emin (emin);
+ set_emax (emax);
+}
+
static void
check_coverage (void)
{
@@ -892,6 +943,7 @@ main (void)
generic_tests ();
check_extreme ();
cancel ();
+ check_overflow ();
check_coverage ();
tests_end_mpfr ();