diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2006-01-12 10:27:27 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2006-01-12 10:27:27 +0000 |
commit | 7c89b9efd01a9bce8864b8742f2d15387a6e757e (patch) | |
tree | 801a936b6d218155e53b51c3127b9b5b7b1fe2e3 /tests/tset_f.c | |
parent | 50c3e23ca77fdc0052ca87a25abb1269f95df583 (diff) | |
download | mpfr-7c89b9efd01a9bce8864b8742f2d15387a6e757e.tar.gz |
More reliable tests for mpfr_set_f (x, y, GMP_RNDN) for
y = 2^emax and y = 2^(emax-1).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3997 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tset_f.c')
-rw-r--r-- | tests/tset_f.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/tests/tset_f.c b/tests/tset_f.c index b4db115e2..9bcadaad0 100644 --- a/tests/tset_f.c +++ b/tests/tset_f.c @@ -31,6 +31,7 @@ main (void) { mpfr_t x, u; mpf_t y, z; + mp_exp_t emax; unsigned long k, pr; int r, inexact; @@ -137,26 +138,38 @@ main (void) mpfr_mul_2ui (u, u, ULONG_MAX, GMP_RNDN); if (!mpfr_equal_p (x, u)) { - printf ("Error: mpfr_set_f (x, y, GMP_RNDN) for y=2^ULONG_MAX\n"); + printf ("Error: mpfr_set_f (x, y, GMP_RNDN) for y = 2^ULONG_MAX\n"); exit (1); } - mpf_set_ui (y, 1); - mpf_mul_2exp (y, y, mpfr_get_emax ()); - mpfr_set_f (x, y, GMP_RNDN); - if (mpfr_inf_p (x) == 0 || mpfr_cmp_ui (x, 0) < 0) + emax = mpfr_get_emax (); + + /* For mpf_mul_2exp, emax must fit in an unsigned long! */ + if (emax >= 0 && emax <= ULONG_MAX) { - printf ("Error: mpfr_set_f (x, y, GMP_RNDN) for y=2^emax\n"); - exit (1); + mpf_set_ui (y, 1); + mpf_mul_2exp (y, y, emax); + mpfr_set_f (x, y, GMP_RNDN); + mpfr_set_ui_2exp (u, 1, emax, GMP_RNDN); + if (!mpfr_equal_p (x, u)) + { + printf ("Error: mpfr_set_f (x, y, GMP_RNDN) for y = 2^emax\n"); + exit (1); + } } - mpf_set_ui (y, 1); - mpf_mul_2exp (y, y, mpfr_get_emax () - 1); - mpfr_set_f (x, y, GMP_RNDN); - if (mpfr_cmp_ui_2exp (x, 1, mpfr_get_emax () - 1) != 0) + /* For mpf_mul_2exp, emax - 1 must fit in an unsigned long! */ + if (emax >= 1 && emax - 1 <= ULONG_MAX) { - printf ("Error: mpfr_set_f (x, y, GMP_RNDN) for y=2^(emax-1)\n"); - exit (1); + mpf_set_ui (y, 1); + mpf_mul_2exp (y, y, emax - 1); + mpfr_set_f (x, y, GMP_RNDN); + mpfr_set_ui_2exp (u, 1, emax - 1, GMP_RNDN); + if (!mpfr_equal_p (x, u)) + { + printf ("Error: mpfr_set_f (x, y, GMP_RNDN) for y = 2^(emax-1)\n"); + exit (1); + } } mpfr_clear (x); |