From abf8081545e3f1d6591fdad7b806d56d7f0ee3b2 Mon Sep 17 00:00:00 2001 From: vlefevre Date: Thu, 23 Jan 2014 12:26:17 +0000 Subject: [tests/tadd.c] Added check_extreme test (huge + tiny). [tests/tsum.c] Added check_extreme test (same test as in tadd.c, but with mpfr_sum instead of mpfr_add), and temporarily disabled the cancel test. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@8877 280ebfd0-de03-0410-8827-d642c229c3f4 --- tests/tadd.c | 37 +++++++++++++++++++++++++++++++++++++ tests/tsum.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) (limited to 'tests') diff --git a/tests/tadd.c b/tests/tadd.c index 043bef2fd..5b01b3993 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -1094,6 +1094,40 @@ tests (void) check_1minuseps (); } +static void +check_extreme (void) +{ + mpfr_t u, v, w, x, y; + int i, inex, r; + + mpfr_inits2 (32, u, v, w, x, y, (mpfr_ptr) 0); + mpfr_setmin (u, mpfr_get_emax ()); + mpfr_setmax (v, mpfr_get_emin ()); + mpfr_setmin (w, mpfr_get_emax () - 40); + RND_LOOP (r) + for (i = 0; i < 2; i++) + { + mpfr_add (x, u, v, (mpfr_rnd_t) r); + mpfr_set_prec (y, 64); + inex = mpfr_add (y, u, w, MPFR_RNDN); + MPFR_ASSERTN (inex == 0); + mpfr_prec_round (y, 32, (mpfr_rnd_t) r); + if (! mpfr_equal_p (x, y)) + { + printf ("Error in check_extreme (%s, i = %d)\n", + mpfr_print_rnd_mode ((mpfr_rnd_t) r), i); + printf ("Expected "); + mpfr_dump (y); + printf ("Got "); + mpfr_dump (x); + exit (1); + } + mpfr_neg (v, v, MPFR_RNDN); + mpfr_neg (w, w, MPFR_RNDN); + } + mpfr_clears (u, v, w, x, y, (mpfr_ptr) 0); +} + #define TEST_FUNCTION test_add #define TWO_ARGS #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS) @@ -1111,6 +1145,9 @@ main (int argc, char *argv[]) usesp = 1; tests (); #endif + + check_extreme (); + test_generic (2, 1000, 100); tests_end_mpfr (); diff --git a/tests/tsum.c b/tests/tsum.c index 3e26dcbf0..6995b521f 100644 --- a/tests/tsum.c +++ b/tests/tsum.c @@ -354,6 +354,41 @@ bug20131027 (void) mpfr_clear (r); } +static void +check_extreme (void) +{ + mpfr_t u, v, w, x, y; + mpfr_ptr t[] = { u, v }; + int i, inex, r; + + mpfr_inits2 (32, u, v, w, x, y, (mpfr_ptr) 0); + mpfr_setmin (u, mpfr_get_emax ()); + mpfr_setmax (v, mpfr_get_emin ()); + mpfr_setmin (w, mpfr_get_emax () - 40); + RND_LOOP (r) + for (i = 0; i < 2; i++) + { + mpfr_sum (x, t, 2, (mpfr_rnd_t) r); + mpfr_set_prec (y, 64); + inex = mpfr_add (y, u, w, MPFR_RNDN); + MPFR_ASSERTN (inex == 0); + mpfr_prec_round (y, 32, (mpfr_rnd_t) r); + if (! mpfr_equal_p (x, y)) + { + printf ("Error in check_extreme (%s, i = %d)\n", + mpfr_print_rnd_mode ((mpfr_rnd_t) r), i); + printf ("Expected "); + mpfr_dump (y); + printf ("Got "); + mpfr_dump (x); + exit (1); + } + mpfr_neg (v, v, MPFR_RNDN); + mpfr_neg (w, w, MPFR_RNDN); + } + mpfr_clears (u, v, w, x, y, (mpfr_ptr) 0); +} + static void cancel (void) { @@ -361,6 +396,10 @@ cancel (void) mpfr_ptr px[2 * MPFR_NCANCEL]; int i, j, n; + /* FIXME: re-enable and improve once mpfr_sum has been fixed. + check_extreme() is currently sufficient to show problems. */ + return; + for (i = 0; i < 8; i++) { for (n = 0; n < numberof (x); n++) @@ -426,6 +465,7 @@ main (void) for (p = 2 ; p < 444 ; p += 17) for (n = 2 ; n < 1026 ; n += 42 + p) test_sum (p, n); + check_extreme (); cancel (); tests_end_mpfr (); -- cgit v1.2.1