summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorthevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4>2009-04-15 17:07:42 +0000
committerthevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4>2009-04-15 17:07:42 +0000
commit8f8741e0b947b38ccdbae60e3125680391a3733d (patch)
treec11ace53cf0bb2db7992103b77f1756bcc699738 /tests
parent0fb4a0ffdc5cce5307bf5c98190f649e2a313a47 (diff)
downloadmpfr-8f8741e0b947b38ccdbae60e3125680391a3733d.tar.gz
get_f.c: remove dead code (x and z always have the same number of limbs).
tests/tget_f.c: Add tests with every rounding mode, add tests with random values. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@6173 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r--tests/tget_f.c179
1 files changed, 85 insertions, 94 deletions
diff --git a/tests/tget_f.c b/tests/tget_f.c
index 03929f560..f521660a3 100644
--- a/tests/tget_f.c
+++ b/tests/tget_f.c
@@ -169,104 +169,95 @@ special_test (void)
static void
ternary_test (void)
{
- int inex;
+ int prec;
+ mpfr_rnd_t rnd;
+ int inex, expected_inex;
mpf_t x;
mpfr_t y;
- mpf_init2 (x, BITS_PER_MP_LIMB);
- mpfr_init2 (y, 2 * BITS_PER_MP_LIMB);
-
- /* y == 1 */
- mpfr_set_ui (y, 1, MPFR_RNDN);
-
- inex = mpfr_get_f (x, y, MPFR_RNDU);
- if (inex != 0 || mpfr_cmp_f (y, x) !=0)
- {
- printf ("Error in mpfr_get_f (x, y, MPFR_RNDU)\n");
- printf ("x = ");
- mpf_dump (x);
- printf ("y = ");
- mpfr_dump (y);
- if (inex != 0)
- printf ("got ternary value = %+d, expected: 0\n", inex);
-
- exit (1);
- }
+ mpf_init2 (x, 256);
+ mpfr_init2 (y, 256);
- inex = mpfr_get_f (x, y, MPFR_RNDD);
- if (inex != 0 || mpfr_cmp_f (y, x) !=0)
+ for (prec = 2; prec <= 256; prec++)
{
- printf ("Error in mpfr_get_f (x, y, MPFR_RNDD)\n");
- printf ("x = ");
- mpf_dump (x);
- printf ("y = ");
- mpfr_dump (y);
- if (inex != 0)
- printf ("got ternary value = %+d, expected: 0\n", inex);
-
- exit (1);
- }
-
- /* y == 1 + epsilon */
- mpfr_nextabove (y);
-
- inex = mpfr_get_f (x, y, MPFR_RNDU);
- if (inex <= 0 || mpfr_cmp_f (y, x) >=0)
- {
- printf ("Error in mpfr_get_f (x, y, MPFR_RNDU)\n");
- printf ("x = ");
- mpf_dump (x);
- printf ("y = ");
- mpfr_dump (y);
- if (inex <= 0)
- printf ("got ternary value = %+d, expected: +1\n", inex);
-
- exit (1);
- }
- inex = mpfr_get_f (x, y, MPFR_RNDD);
- if (inex >= 0 || mpfr_cmp_f (y, x) <=0)
- {
- printf ("Error in mpfr_get_f (x, y, MPFR_RNDD)\n");
- printf ("x = ");
- mpf_dump (x);
- printf ("y = ");
- mpfr_dump (y);
- if (inex >= 0)
- printf ("got ternary value = %+d, expected: -1\n", inex);
-
- exit (1);
- }
-
- /* y == -1 - epsilon */
- mpfr_neg (y, y, MPFR_RNDN);
-
- inex = mpfr_get_f (x, y, MPFR_RNDU);
- if (inex <= 0 || mpfr_cmp_f (y, x) >=0)
- {
- printf ("Error in mpfr_get_f (x, y, MPFR_RNDU)\n");
- printf ("x = ");
- mpf_dump (x);
- printf ("y = ");
- mpfr_dump (y);
- if (inex <= 0)
- printf ("got ternary value = %+d, expected: +1\n", inex);
-
- exit (1);
- }
-
- inex = mpfr_get_f (x, y, MPFR_RNDD);
- if (inex >= 0 || mpfr_cmp_f (y, x) <=0)
- {
- printf ("Error in mpfr_get_f (x, y, MPFR_RNDD)\n");
- printf ("x = ");
- mpf_dump (x);
- printf ("y = ");
- mpfr_dump (y);
- if (inex >= 0)
- printf ("got ternary value = %+d, expected: -1\n", inex);
-
- exit (1);
+ mpf_set_prec (x, prec);
+ mpfr_set_prec (y, PREC (x) * BITS_PER_MP_LIMB + 1);
+
+ /* y == 1 */
+ mpfr_set_ui_2exp (y, 1, prec, MPFR_RNDN);
+
+ RND_LOOP (rnd)
+ {
+ inex = mpfr_get_f (x, y, rnd);
+
+ if (inex != 0 || mpfr_cmp_f (y, x) !=0)
+ {
+ printf ("Error in mpfr_get_f (x, y, %s)\nx = ",
+ mpfr_print_rnd_mode (rnd));
+ mpf_out_str (stdout, 2, 0, x);
+ printf ("\ny = ");
+ mpfr_dump (y);
+ if (inex != 0)
+ printf ("got ternary value = %+d, expected: 0\n", inex);
+
+ exit (1);
+ }
+ }
+
+ /* y == 1 + epsilon */
+ mpfr_nextbelow (y);
+
+ RND_LOOP (rnd)
+ {
+ switch (rnd)
+ {
+ case MPFR_RNDU: case MPFR_RNDA:
+ case MPFR_RNDN:
+ expected_inex = +1;
+ break;
+ default :
+ expected_inex = -1;
+ }
+
+ inex = mpfr_get_f (x, y, rnd);
+
+ if (! SAME_SIGN (expected_inex, inex)
+ || SAME_SIGN (expected_inex, mpfr_cmp_f (y, x)))
+ {
+ printf ("Error in mpfr_get_f (x, y, %s)\nx = ",
+ mpfr_print_rnd_mode (rnd));
+ mpf_out_str (stdout, 2, 0, x);
+ printf ("\ny = ");
+ mpfr_dump (y);
+ if (! SAME_SIGN (expected_inex, inex))
+ printf ("got ternary value = %+d, expected: %+d\n",
+ inex, expected_inex);
+
+ exit (1);
+ }
+ }
+
+ /* y == positive random float */
+ mpfr_random2 (y, MPFR_LIMB_SIZE (y), 1024, RANDS);
+
+ RND_LOOP (rnd)
+ {
+ inex = mpfr_get_f (x, y, rnd);
+
+ if (! SAME_SIGN (inex, -mpfr_cmp_f (y, x)))
+ {
+ printf ("Error in mpfr_get_f (x, y, %s)\nx = ",
+ mpfr_print_rnd_mode (rnd));
+ mpf_out_str (stdout, 2, 0, x);
+ printf ("\ny = ");
+ mpfr_dump (y);
+ printf ("got ternary value = %+d, expected: %+d\n",
+ inex, -mpfr_cmp_f (y, x));
+
+ exit (1);
+ }
+ }
}
mpf_clear (x);
@@ -349,7 +340,7 @@ main (void)
mpfr_dump (y);
printf ("x=");
mpf_div_2exp (x, x, e);
- mpf_dump (x);
+ mpf_out_str (stdout, 2, 0, x);
exit (1);
}
@@ -365,7 +356,7 @@ main (void)
mpfr_dump (y);
printf ("x=");
mpf_mul_2exp (x, x, e);
- mpf_dump (x);
+ mpf_out_str (stdout, 2, 0, x);
exit (1);
}
}