diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-06 12:30:41 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-06 12:30:41 +0000 |
commit | 7d40814b714eb46837b2909d146e5a5008e332cf (patch) | |
tree | d6c8c9ededbc96c2779ee48d60a021dc132f09dc /tests | |
parent | 523e3a6ffb2e29853cb75ad1f7a7df71bccb246f (diff) | |
download | mpfr-7d40814b714eb46837b2909d146e5a5008e332cf.tar.gz |
Add the tests to check if 0 for signed class with unsigned 0 is set to 0+.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2595 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tset_f.c | 22 | ||||
-rw-r--r-- | tests/tset_q.c | 25 | ||||
-rw-r--r-- | tests/tset_si.c | 34 | ||||
-rw-r--r-- | tests/tset_z.c | 24 |
4 files changed, 87 insertions, 18 deletions
diff --git a/tests/tset_f.c b/tests/tset_f.c index f61942cb8..9d85566a5 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; unsigned long k, pr; + int r, inexact; tests_start_mpfr (); @@ -71,17 +72,32 @@ main (void) } mpfr_clear(u); - mpfr_clear(x); for (k = 1; k <= 100000; k++) { pr = 2 + (randlimb () & 255); mpf_set_prec (z, pr); mpf_random2 (z, z->_mp_prec, 0); - mpfr_init2 (x, pr); + mpfr_set_prec (x, pr); mpfr_set_f (x, z, 0); - mpfr_clear (x); } + + /* Check for +0 */ + mpfr_set_prec(x, 53); + mpf_set_prec(y, 53); + mpf_set_ui(y, 0); + for(r = 0 ; r < 4 ; r++) + { + inexact = mpfr_set_f(x, y, r); + if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact) + { + printf("mpfr_set_f(x,0) failed for %s\n", + mpfr_print_rnd_mode(r)); + exit(1); + } + } + + mpfr_clear (x); mpf_clear (y); mpf_clear (z); diff --git a/tests/tset_q.c b/tests/tset_q.c index 2e718ef9c..6f84c8776 100644 --- a/tests/tset_q.c +++ b/tests/tset_q.c @@ -71,6 +71,29 @@ check (long int n, long int d, mp_rnd_t rnd, double y) mpq_clear (q); } +static void check0(void) +{ + mpq_t y; + mpfr_t x; + int inexact, r; + /* Check for +0 */ + mpfr_init(x); + mpq_init(y); + mpq_set_si(y, 0, 1); + for(r = 0 ; r < 4 ; r++) + { + inexact = mpfr_set_q(x, y, r); + if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact) + { + printf("mpfr_set_q(x,0) failed for %s\n", + mpfr_print_rnd_mode(r)); + exit(1); + } + } + mpfr_clear(x); + mpq_clear(y); +} + int main (void) { @@ -86,6 +109,8 @@ main (void) check(632549085, 1831935802, GMP_RNDN, 3.4528998467600230393e-1); check (1, 1, GMP_RNDN, 1.0); + check0(); + tests_end_mpfr (); return 0; } diff --git a/tests/tset_si.c b/tests/tset_si.c index 1a0864280..ea0254114 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -36,6 +36,7 @@ main (int argc, char *argv[]) long k, z, d, N; unsigned long zl, dl; int inex; + int r; tests_start_mpfr (); @@ -129,22 +130,27 @@ main (int argc, char *argv[]) exit (1); } - mpfr_set_si (x, -1, GMP_RNDN); - mpfr_set_ui (x, 0, GMP_RNDN); - if (MPFR_SIGN (x) < 0) - { - printf ("mpfr_set_ui (x, 0) gives -0\n"); - exit (1); - } - - mpfr_set_si (x, -1, GMP_RNDN); - mpfr_set_si (x, 0, GMP_RNDN); - if (MPFR_SIGN (x) < 0) + for(r = 0 ; r < 4 ; r++) { - printf ("mpfr_set_si (x, 0) gives -0\n"); - exit (1); + mpfr_set_si (x, -1, r); + mpfr_set_ui (x, 0, r); + if (MPFR_IS_NEG (x) ) + { + printf ("mpfr_set_ui (x, 0) gives -0 for %s\n", + mpfr_print_rnd_mode(r)); + exit (1); + } + + mpfr_set_si (x, -1, r); + mpfr_set_si (x, 0, r); + if (MPFR_IS_NEG (x) ) + { + printf ("mpfr_set_si (x, 0) gives -0 for %s\n", + mpfr_print_rnd_mode(r) ); + exit (1); + } } - + /* check potential bug in case mp_limb_t is unsigned */ mpfr_set_emax (0); mpfr_set_si (x, -1, GMP_RNDN); diff --git a/tests/tset_z.c b/tests/tset_z.c index 73b3f11f4..33b6abce6 100644 --- a/tests/tset_z.c +++ b/tests/tset_z.c @@ -26,12 +26,33 @@ MA 02111-1307, USA. */ #include "mpfr-test.h" +static void check0(void) +{ + mpz_t y; + mpfr_t x; + int inexact, r; + /* Check for +0 */ + mpfr_init(x); + mpz_init(y); + mpz_set_si(y, 0); + for(r = 0 ; r < 4 ; r++) + { + inexact = mpfr_set_z(x, y, r); + if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact) + { + printf("mpfr_set_z(x,0) failed for %s\n", + mpfr_print_rnd_mode(r)); + exit(1); + } + } + mpfr_clear(x); + mpz_clear(y); +} /* FIXME: It'd be better to examine the actual data in an mpfr_t to see that it's as expected. Comparing mpfr_set_z with mpfr_cmp or against mpfr_get_si is a rather indirect test of a low level routine. */ - static void check (long i, unsigned char rnd) { @@ -84,6 +105,7 @@ main (int argc, char *argv[]) check (0, 0); for (j = 0; j < 200000; j++) check (randlimb () & LONG_MAX, randlimb () % 4); + check0(); tests_end_mpfr (); return 0; |