summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-02-25 14:05:40 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-02-25 14:05:40 +0000
commit75d96d6aa1aa962dc60783ac5f61c7a34264a0a6 (patch)
treeea69e250c1df71b7454381ce447de5aae6eba4a5
parent94380295066ee140093bc86895999971e59accd7 (diff)
downloadmpfr-75d96d6aa1aa962dc60783ac5f61c7a34264a0a6.tar.gz
[tests/tsum.c] New tests.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/new-sum@9320 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--tests/tsum.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/tsum.c b/tests/tsum.c
index c45efc3a7..14f12b47f 100644
--- a/tests/tsum.c
+++ b/tests/tsum.c
@@ -310,6 +310,81 @@ check_more_special (void)
mpfr_clear (sum);
}
+/* i * 2^46 + j * 2^45 + k * 2^44 + f * 2^(-2),
+ with -1 <= i, j, k <= 1, i != 0, -3 <= f <= 3,
+ ulp(exact sum) = 2^0 and ulp(exact sum) = 2^44. */
+static void
+check1 (void)
+{
+ mpfr_t sum1, sum2, s1, s2, s3, t[4];
+ mpfr_ptr p[4];
+ int i, j, k, f, prec, r, inex1, inex2;
+
+ mpfr_init2 (sum1, 47);
+ mpfr_init2 (sum2, 47);
+ mpfr_init2 (s1, 3);
+ mpfr_init2 (s2, 3);
+ mpfr_init2 (s3, 49);
+ for (i = 0; i < 4; i++)
+ {
+ mpfr_init2 (t[i], 2);
+ p[i] = t[i];
+ }
+
+ for (i = -1; i <= 1; i += 2)
+ {
+ mpfr_set_si_2exp (t[0], i, 46, MPFR_RNDN);
+ for (j = -1; j <= 1; j++)
+ {
+ mpfr_set_si_2exp (t[1], j, 45, MPFR_RNDN);
+ inex1 = mpfr_add (s1, t[0], t[1], MPFR_RNDN);
+ MPFR_ASSERTN (inex1 == 0);
+ for (k = -1; k <= 1; k++)
+ {
+ mpfr_set_si_2exp (t[2], k, 44, MPFR_RNDN);
+ inex1 = mpfr_add (s2, s1, t[2], MPFR_RNDN);
+ MPFR_ASSERTN (inex1 == 0);
+ for (f = -3; f <= 3; f++)
+ {
+ mpfr_set_si_2exp (t[3], f, -2, MPFR_RNDN);
+ inex1 = mpfr_add (s3, s2, t[3], MPFR_RNDN);
+ MPFR_ASSERTN (inex1 == 0);
+ for (prec = mpfr_get_exp (s3);
+ prec >= MPFR_PREC_MIN;
+ prec -= 44)
+ {
+ mpfr_set_prec (sum1, prec);
+ mpfr_set_prec (sum2, prec);
+ RND_LOOP (r)
+ {
+ inex1 = mpfr_set (sum1, s3, (mpfr_rnd_t) r);
+ inex2 = mpfr_sum (sum2, p, 4, (mpfr_rnd_t) r);
+ if (! mpfr_equal_p (sum1, sum2) || inex1 != inex2)
+ {
+ printf ("Error in check1 on %s, prec = %d, "
+ "i = %d, j = %d, k = %d, f = %d\n",
+ mpfr_print_rnd_mode ((mpfr_rnd_t) r),
+ prec, i, j, k, f);
+ printf ("Expected ");
+ mpfr_dump (sum1);
+ printf ("with inex = %d\n", inex1);
+ printf ("Got ");
+ mpfr_dump (sum2);
+ printf ("with inex = %d\n", inex2);
+ exit (1);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ for (i = 0; i < 4; i++)
+ mpfr_clear (t[i]);
+ mpfr_clears (sum1, sum2, s1, s2, s3, (mpfr_ptr) 0);
+}
+
/* bug reported by Joseph S. Myers on 2013-10-27
https://sympa.inria.fr/sympa/arc/mpfr/2013-10/msg00015.html */
static void
@@ -489,6 +564,7 @@ main (void)
check_special ();
check_more_special ();
+ check1 ();
bug20131027 ();
generic_tests ();
check_extreme ();