From b593678522fbbf1ef12a51628a044a8fbe18c47c Mon Sep 17 00:00:00 2001 From: vlefevre Date: Mon, 30 Mar 2015 13:15:00 +0000 Subject: [tests/tsum.c] Extend the check4 test even further. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/new-sum@9352 280ebfd0-de03-0410-8827-d642c229c3f4 --- tests/tsum.c | 107 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/tests/tsum.c b/tests/tsum.c index 17921eed4..c6b296245 100644 --- a/tests/tsum.c +++ b/tests/tsum.c @@ -559,15 +559,15 @@ check3 (void) } /* Try to check MPFR_RNDN, tmd=2, rbit=0, sst=0 or 1, negative with: - * s * (2^n - 2^k) + h + 2^(-1) * i + 2^(-1) * j, with -1 <= h, i, j <= 1, - * s = -1 or 1, prec n-k. + * s * (q * 2^(n-1) - 2^k) + h + 2^(-1) * i + 2^(-1) * j, + * with -1 <= h, i, j <= 1, 2 <= q <= 3, s = -1 or 1, prec n-k. */ static void check4 (void) { mpfr_t sum1, sum2, s1, s2, s3, s4, t[5]; mpfr_ptr p[5]; - int h, i, j, k, n, r, s, prec, inex1, inex2; + int h, i, j, k, n, q, r, s, prec, inex1, inex2; mpfr_inits2 (256, sum1, sum2, s1, s2, s3, s4, (mpfr_ptr) 0); for (i = 0; i < 5; i++) @@ -576,60 +576,61 @@ check4 (void) p[i] = t[i]; } - for (h = -1; h <= 1; h++) - { - mpfr_set_si (t[0], h, MPFR_RNDN); - for (i = -1; i <= 1; i++) - { - mpfr_set_si (t[1], i, MPFR_RNDN); - inex1 = mpfr_add (s1, t[0], t[1], MPFR_RNDN); - MPFR_ASSERTN (inex1 == 0); - for (j = -1; j <= 1; j++) - { - mpfr_set_si (t[2], j, MPFR_RNDN); - inex1 = mpfr_add (s2, s1, t[2], MPFR_RNDN); + /* No GNU style for the many nested loops... */ + for (k = 1; k <= 240; k++) { + mpfr_set_si_2exp (t[0], -1, k, MPFR_RNDN); + for (n = k + 2; n <= 255; n++) { + prec = n - k; + mpfr_set_prec (sum1, prec); + mpfr_set_prec (sum2, prec); + for (q = 2; q <= 3; q++) { + mpfr_set_si_2exp (t[1], q, n - 1, MPFR_RNDN); + inex1 = mpfr_add (s1, t[0], t[1], MPFR_RNDN); + MPFR_ASSERTN (inex1 == 0); + for (s = -1; s <= 1; s += 2) { + mpfr_neg (t[0], t[0], MPFR_RNDN); + mpfr_neg (t[1], t[1], MPFR_RNDN); + mpfr_neg (s1, s1, MPFR_RNDN); + for (h = -1; h <= 1; h++) { + mpfr_set_si (t[2], h, MPFR_RNDN); + inex1 = mpfr_add (s2, s1, t[2], MPFR_RNDN); + MPFR_ASSERTN (inex1 == 0); + for (i = -1; i <= 1; i++) { + mpfr_set_si (t[3], i, MPFR_RNDN); + inex1 = mpfr_add (s3, s2, t[3], MPFR_RNDN); MPFR_ASSERTN (inex1 == 0); - for (s = -1; s <= 1; s += 2) - for (k = 1; k <= 240; k++) - { - mpfr_set_si_2exp (t[3], -s, k, MPFR_RNDN); - inex1 = mpfr_add (s3, s2, t[3], MPFR_RNDN); - MPFR_ASSERTN (inex1 == 0); - for (n = k + 2; n <= 255; n++) - { - prec = n - k; - mpfr_set_prec (sum1, prec); - mpfr_set_prec (sum2, prec); - mpfr_set_si_2exp (t[4], s, n, MPFR_RNDN); - inex1 = mpfr_add (s4, s3, t[4], MPFR_RNDN); - MPFR_ASSERTN (inex1 == 0); - RND_LOOP (r) - { - inex1 = mpfr_set (sum1, s4, (mpfr_rnd_t) r); - inex2 = mpfr_sum (sum2, p, 5, (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 check4 on %s, prec = %d, " - "i = %d, j = %d, k = %d, n = %d\n", - mpfr_print_rnd_mode ((mpfr_rnd_t) r), - prec, i, j, k, n); - 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 (j = -1; j <= 1; j++) { + mpfr_set_si (t[4], j, MPFR_RNDN); + inex1 = mpfr_add (s4, s3, t[4], MPFR_RNDN); + MPFR_ASSERTN (inex1 == 0); + RND_LOOP (r) { + inex1 = mpfr_set (sum1, s4, (mpfr_rnd_t) r); + inex2 = mpfr_sum (sum2, p, 5, (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 check4 on %s, k = %d, n = %d " + "(prec %d), q = %d, s = %d, i = %d, j = %d\n", + mpfr_print_rnd_mode ((mpfr_rnd_t) r), + k, n, prec, q, s, i, j); + 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 < 5; i++) mpfr_clear (t[i]); -- cgit v1.2.1