diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-01-04 02:57:08 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-01-04 02:57:08 +0000 |
commit | fc14d0126c36bb74758aed6e24281f13e1590407 (patch) | |
tree | 90828a9cc56b328b18ea7c8e7bfed1991f431d56 /tests/tcmp2.c | |
parent | 36cf516e629da8c294bc7359916a7eb263e9989c (diff) | |
download | mpfr-fc14d0126c36bb74758aed6e24281f13e1590407.tar.gz |
Optimization: mpfr_cmp2 now accepts any combination of real arguments
and computes the sign of |b| - |c| (in addition to the number of
cancelled bits); mpfr_add, mpfr_sub, mpfr_sub1, mpfr_agm and some
tests updated to take this change into account.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1641 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tcmp2.c')
-rw-r--r-- | tests/tcmp2.c | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/tests/tcmp2.c b/tests/tcmp2.c index 61bfaaa1c..70349fd40 100644 --- a/tests/tcmp2.c +++ b/tests/tcmp2.c @@ -57,7 +57,8 @@ void worst_cases () { mpfr_t x, y; - unsigned int i, j, k, l, b, expected; + unsigned int i, j, k, b, expected; + mp_prec_t l; mpfr_init2 (x, 200); mpfr_init2 (y, 200); @@ -68,24 +69,26 @@ worst_cases () mpfr_set_ui (x, 1, GMP_RNDN); mpfr_div_2exp (y, y, 1, GMP_RNDN); /* y = 1/2^i */ - if ((l = mpfr_cmp2 (x, y)) != 1) + l = 0; + if (mpfr_cmp2 (x, y, &l) <= 0 || l != 1) { fprintf (stderr, "Error in mpfr_cmp2:\nx="); mpfr_out_str (stderr, 2, 0, x, GMP_RNDN); fprintf (stderr, "\ny="); mpfr_out_str (stderr, 2, 0, y, GMP_RNDN); - fprintf (stderr, "\ngot %u instead of %u\n", l, 1); + fprintf (stderr, "\ngot %lu instead of %u\n", l, 1); exit(1); } mpfr_add (x, x, y, GMP_RNDN); /* x = 1 + 1/2^i */ - if ((l = mpfr_cmp2 (x, y)) != 0) + l = 0; + if (mpfr_cmp2 (x, y, &l) <= 0 || l != 0) { fprintf (stderr, "Error in mpfr_cmp2:\nx="); mpfr_out_str (stderr, 2, 0, x, GMP_RNDN); fprintf (stderr, "\ny="); mpfr_out_str (stderr, 2, 0, y, GMP_RNDN); - fprintf (stderr, "\ngot %u instead of %u\n", l, 0); + fprintf (stderr, "\ngot %lu instead of %u\n", l, 0); exit(1); } } @@ -110,7 +113,7 @@ worst_cases () set_bit (x, i + j + k + 2, 1); set_bit (y, i + j + k + 2, 0); - l = mpfr_cmp2 (x, y); + l = 0; mpfr_cmp2 (x, y, &l); expected = i + j + k + 1; if (l != expected) { @@ -118,14 +121,14 @@ worst_cases () mpfr_out_str (stderr, 2, 0, x, GMP_RNDN); fprintf (stderr, "\ny="); mpfr_out_str (stderr, 2, 0, y, GMP_RNDN); - fprintf (stderr, "\ngot %u instead of %u\n", l, expected); + fprintf (stderr, "\ngot %lu instead of %u\n", l, expected); exit(1); } set_bit (x, i + j + k + 2, 0); set_bit (x, i + j + k + 3, 0); set_bit (y, i + j + k + 3, 1); - l = mpfr_cmp2 (x, y); + l = 0; mpfr_cmp2 (x, y, &l); expected = i + j + k + 2; if (l != expected) { @@ -133,7 +136,7 @@ worst_cases () mpfr_out_str (stderr, 2, 0, x, GMP_RNDN); fprintf (stderr, "\ny="); mpfr_out_str (stderr, 2, 0, y, GMP_RNDN); - fprintf (stderr, "\ngot %u instead of %u\n", l, expected); + fprintf (stderr, "\ngot %lu instead of %u\n", l, expected); exit(1); } } @@ -148,7 +151,7 @@ void tcmp2 (double x, double y, int i) { mpfr_t xx, yy; - int j; + mp_prec_t j; if (i==-1) { if (x==y) i=53; @@ -157,13 +160,25 @@ tcmp2 (double x, double y, int i) mpfr_init2(xx, 53); mpfr_init2(yy, 53); mpfr_set_d (xx, x, GMP_RNDN); mpfr_set_d (yy, y, GMP_RNDN); - j = mpfr_cmp2 (xx, yy); - if (j != i) { + j = 0; + if (mpfr_cmp2 (xx, yy, &j) == 0) + { + if (x != y) + { + fprintf (stderr, "Error in mpfr_cmp2 for\nx="); + mpfr_out_str (stderr, 2, 0, xx, GMP_RNDN); + fprintf (stderr, "\ny="); + mpfr_out_str (stderr, 2, 0, yy, GMP_RNDN); + fprintf (stderr, "\ngot sign 0 for x != y\n"); + exit(1); + } + } + else if (j != i) { fprintf (stderr, "Error in mpfr_cmp2 for\nx="); mpfr_out_str (stderr, 2, 0, xx, GMP_RNDN); fprintf (stderr, "\ny="); mpfr_out_str (stderr, 2, 0, yy, GMP_RNDN); - fprintf (stderr, "\ngot %u instead of %u\n", j, i); + fprintf (stderr, "\ngot %lu instead of %u\n", j, i); exit(1); } mpfr_clear(xx); mpfr_clear(yy); @@ -172,7 +187,7 @@ tcmp2 (double x, double y, int i) void special () { mpfr_t x, y; - int j; + mp_prec_t j; mpfr_init (x); mpfr_init (y); @@ -181,7 +196,8 @@ void special () mpfr_set_prec (y, 65); mpfr_set_str_raw (x, "0.10000000000000000000000000000000000001110010010110100110011110000E1"); mpfr_set_str_raw (y, "0.11100100101101001100111011111111110001101001000011101001001010010E-35"); - if ((j = mpfr_cmp2 (x, y)) != 1) { + j = 0; + if (mpfr_cmp2 (x, y, &j) <= 0 || j != 1) { printf ("Error in mpfr_cmp2:\n"); printf ("x="); mpfr_print_binary (x); @@ -189,29 +205,31 @@ void special () printf ("y="); mpfr_print_binary (y); putchar ('\n'); - printf ("got %d, expected 1\n", j); + printf ("got %lu, expected 1\n", j); exit (1); } mpfr_set_prec(x, 127); mpfr_set_prec(y, 127); mpfr_set_str_raw(x, "0.1011010000110111111000000101011110110001000101101011011110010010011110010000101101000010011001100110010000000010110000101000101E6"); mpfr_set_str_raw(y, "0.1011010000110111111000000101011011111100011101000011001111000010100010100110110100110010011001100110010000110010010110000010110E6"); - if ((j=mpfr_cmp2(x, y)) != 32) { + j = 0; + if (mpfr_cmp2(x, y, &j) <= 0 || j != 32) { printf("Error in mpfr_cmp2:\n"); printf("x="); mpfr_print_binary(x); putchar('\n'); printf("y="); mpfr_print_binary(y); putchar('\n'); - printf("got %d, expected 32\n", j); + printf("got %lu, expected 32\n", j); exit(1); } mpfr_set_prec (x, 128); mpfr_set_prec (y, 239); mpfr_set_str_raw (x, "0.10001000110110000111011000101011111100110010010011001101000011111010010110001000000010100110100111111011011010101100100000000000E167"); mpfr_set_str_raw (y, "0.10001000110110000111011000101011111100110010010011001101000011111010010110001000000010100110100111111011011010101100011111111111111111111111111111111111111111111111011111100101011100011001101000100111000010000000000101100110000111111000101E167"); - if ((j=mpfr_cmp2(x, y)) != 164) { + j = 0; + if (mpfr_cmp2(x, y, &j) <= 0 || j != 164) { printf("Error in mpfr_cmp2:\n"); printf("x="); mpfr_print_binary(x); putchar('\n'); printf("y="); mpfr_print_binary(y); putchar('\n'); - printf("got %d, expected 164\n", j); + printf("got %lu, expected 164\n", j); exit(1); } @@ -219,11 +237,12 @@ void special () mpfr_set_prec (x, 130); mpfr_set_prec (y, 130); mpfr_set_str_raw (x, "0.1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E2"); mpfr_set_str_raw (y, "0.1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100E2"); - if ((j=mpfr_cmp2(x, y)) != 127) { + j = 0; + if (mpfr_cmp2(x, y, &j) <= 0 || j != 127) { printf("Error in mpfr_cmp2:\n"); printf("x="); mpfr_print_binary(x); putchar('\n'); printf("y="); mpfr_print_binary(y); putchar('\n'); - printf("got %d, expected 127\n", j); + printf("got %lu, expected 127\n", j); exit(1); } @@ -231,11 +250,12 @@ void special () mpfr_set_prec (x, 65); mpfr_set_prec (y, 65); mpfr_set_ui (x, 5, GMP_RNDN); mpfr_set_str_raw (y, "0.10011111111111111111111111111111111111111111111111111111111111101E3"); - if ((j=mpfr_cmp2(x, y)) != 63) { + j = 0; + if (mpfr_cmp2(x, y, &j) <= 0 || j != 63) { printf("Error in mpfr_cmp2:\n"); printf("x="); mpfr_print_binary(x); putchar('\n'); printf("y="); mpfr_print_binary(y); putchar('\n'); - printf("got %d, expected 63\n", j); + printf("got %lu, expected 63\n", j); exit(1); } @@ -243,11 +263,12 @@ void special () mpfr_set_prec (x, 65); mpfr_set_prec (y, 65); mpfr_set_str_raw (x, "0.10011011111000101001110000000000000000000000000000000000000000000E-69"); mpfr_set_str_raw (y, "0.10011011111000101001101111111111111111111111111111111111111111101E-69"); - if ((j=mpfr_cmp2(x, y)) != 63) { + j = 0; + if (mpfr_cmp2(x, y, &j) <= 0 || j != 63) { printf("Error in mpfr_cmp2:\n"); printf("x="); mpfr_print_binary(x); putchar('\n'); printf("y="); mpfr_print_binary(y); putchar('\n'); - printf("got %d, expected 63\n", j); + printf("got %lu, expected 63\n", j); exit(1); } |