summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/mpf_compat.h16
-rw-r--r--tests/reuse.c383
-rw-r--r--tests/tabs.c174
-rw-r--r--tests/tacos.c4
-rw-r--r--tests/tadd.c251
-rw-r--r--tests/tagm.c12
-rw-r--r--tests/tasin.c4
-rw-r--r--tests/tatan.c18
-rw-r--r--tests/tcan_round.c6
-rw-r--r--tests/tcbrt.c28
-rw-r--r--tests/tcmp.c130
-rw-r--r--tests/tcmp2.c239
-rw-r--r--tests/tcmp_d.c18
-rw-r--r--tests/tcmp_ui.c22
-rw-r--r--tests/tconst_log2.c24
-rw-r--r--tests/tconst_pi.c2
-rw-r--r--tests/tcos.c20
-rw-r--r--tests/tdiv.c252
-rw-r--r--tests/tdiv_ui.c88
-rw-r--r--tests/teq.c66
-rw-r--r--tests/terf.c88
-rw-r--r--tests/tests.c10
-rw-r--r--tests/texceptions.c46
-rw-r--r--tests/texp.c40
-rw-r--r--tests/texp2.c12
-rw-r--r--tests/tfactorial.c10
-rw-r--r--tests/tfma.c102
-rw-r--r--tests/tfrac.c48
-rw-r--r--tests/tgamma.c8
-rw-r--r--tests/tgeneric.c94
-rw-r--r--tests/tget_d.c7
-rw-r--r--tests/tget_str.c75
-rw-r--r--tests/thypot.c116
-rw-r--r--tests/tisnan.c110
-rw-r--r--tests/tlog.c40
-rw-r--r--tests/tlog10.c4
-rw-r--r--tests/tmul.c90
-rw-r--r--tests/tmul_2exp.c63
-rw-r--r--tests/tmul_ui.c73
-rw-r--r--tests/tout_str.c9
-rw-r--r--tests/tpow.c96
-rw-r--r--tests/tpow3.c100
-rw-r--r--tests/trandom.c7
43 files changed, 1548 insertions, 1457 deletions
diff --git a/tests/mpf_compat.h b/tests/mpf_compat.h
index d5f5390de..21b851fea 100644
--- a/tests/mpf_compat.h
+++ b/tests/mpf_compat.h
@@ -43,24 +43,24 @@ main ()
int i;
FILE *f;
gmp_randstate_t state;
-
+
/* Initialization Functions */
prec = 53;
mpf_set_default_prec (prec);
prec2 = mpf_get_default_prec ();
if (prec2 < prec)
{
- fprintf (stderr, "Error in get_default_prec: %lu < %lu\n", prec2, prec);
+ printf ("Error in get_default_prec: %lu < %lu\n", prec2, prec);
exit (1);
}
mpf_init (y);
mpf_init2 (x, prec);
- prec2 = mpf_get_prec (x);
+ prec2 = mpf_get_prec (x);
if (prec2 < prec)
{
- fprintf (stderr, "Error in get_prec: %lu < %lu\n", prec2, prec);
+ printf ("Error in get_prec: %lu < %lu\n", prec2, prec);
exit (1);
}
@@ -68,7 +68,7 @@ main ()
prec2 = mpf_get_prec (x);
if (prec2 < 2 * prec)
{
- fprintf (stderr, "Error in set_prec: %lu < %lu\n", prec2, 2 * prec);
+ printf ("Error in set_prec: %lu < %lu\n", prec2, 2 * prec);
exit (1);
}
@@ -76,7 +76,7 @@ main ()
prec2 = mpf_get_prec (x);
if (prec2 < prec)
{
- fprintf (stderr, "Error in set_prec_raw: %lu < %lu\n", prec2, prec);
+ printf ("Error in set_prec_raw: %lu < %lu\n", prec2, prec);
exit (1);
}
@@ -89,7 +89,7 @@ main ()
mpz_init_set_ui (z, 17);
mpf_set_z (x, z);
- mpz_clear (z);
+ mpz_clear (z);
mpq_init (q);
mpq_set_ui (q, 2, 3);
@@ -156,7 +156,7 @@ main ()
f = fopen ("/dev/null", "w");
mpf_out_str (f, 10, 10, x);
fclose (f);
-
+
f = fopen ("/dev/null", "r");
mpf_inp_str (x, f, 10);
fclose (f);
diff --git a/tests/reuse.c b/tests/reuse.c
index 8e49a38d6..3fc72ba98 100644
--- a/tests/reuse.c
+++ b/tests/reuse.c
@@ -1,6 +1,6 @@
/* Test file for in-place operations.
-Copyright 2000, 2001, 2002 Free Software Foundation.
+Copyright 2000, 2001, 2002, 2003 Free Software Foundation.
This file is part of the MPFR Library.
@@ -42,7 +42,7 @@ int mpfr_compare _PROTO ((mpfr_t, mpfr_t));
int
mpfr_compare (mpfr_t a, mpfr_t b)
{
- return (MPFR_IS_NAN(a)) ? !MPFR_IS_NAN(b) :
+ return (MPFR_IS_NAN(a)) ? !MPFR_IS_NAN(b) :
(MPFR_IS_NAN(b) || mpfr_cmp(a, b));
}
@@ -80,29 +80,31 @@ test3 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
/* reference call: foo(a, b, c) */
testfunc (ref1, ref2, ref3, rnd);
-
+
/* foo(a, a, c) */
mpfr_set (res1, ref2, rnd); /* exact operation */
testfunc (res1, res1, ref3, rnd);
-
- if (mpfr_compare (res1, ref1)) {
- fprintf (stderr, "Error for %s(a, a, c) for a=%e, c=%e\n", foo,
- mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (res1));
- exit (1);
- }
+
+ if (mpfr_compare (res1, ref1))
+ {
+ printf ("Error for %s(a, a, c) for a=%e, c=%e\n", foo,
+ mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (res1));
+ exit (1);
+ }
/* foo(a, b, a) */
mpfr_set (res1, ref3, rnd);
testfunc (res1, ref2, res1, rnd);
- if (mpfr_compare (res1, ref1)) {
- fprintf (stderr, "Error for %s(a, b, a) for b=%e, a=%e\n", foo,
- mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (res1));
- exit (1);
- }
+ if (mpfr_compare (res1, ref1))
+ {
+ printf ("Error for %s(a, b, a) for b=%e, a=%e\n", foo,
+ mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (res1));
+ exit (1);
+ }
/* foo(a, a, a) */
mpfr_set (ref3, ref2, rnd);
@@ -110,13 +112,14 @@ test3 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
mpfr_set (res1, ref2, rnd);
testfunc (res1, res1, res1, rnd);
- if (mpfr_compare (res1, ref1)) {
- fprintf (stderr, "Error for %s(a, a, a) for a=%e\n", foo,
- mpfr_get_d1 (ref2));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (res1));
- exit (1);
- }
+ if (mpfr_compare (res1, ref1))
+ {
+ printf ("Error for %s(a, a, a) for a=%e\n", foo,
+ mpfr_get_d1 (ref2));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (res1));
+ exit (1);
+ }
}
mpfr_clear (ref1);
@@ -144,9 +147,8 @@ test4 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
/* for each variable, consider each of the following 6 possibilities:
NaN, +Infinity, -Infinity, +0, -0 or a random number */
- for (i=0; i<6; i++)
+ for (i=0; i<6; i++)
{
-
MPFR_CLEAR_FLAGS(op1);
if (i==0) mpfr_set_nan (op1);
if (i==1) mpfr_set_inf (op1, 1);
@@ -154,10 +156,9 @@ test4 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
if (i==3) mpfr_set_d (op1, 0.0, GMP_RNDN);
if (i==4) mpfr_set_d (op1, -0.0, GMP_RNDN);
if (i==5) mpfr_random (op1);
-
- for (j=0; j<6; j++)
- {
+ for (j=0; j<6; j++)
+ {
MPFR_CLEAR_FLAGS(op2);
if (j==0) mpfr_set_nan (op2);
if (j==1) mpfr_set_inf (op2, 1);
@@ -166,9 +167,8 @@ test4 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
if (j==4) mpfr_set_d (op2, -0.0, GMP_RNDN);
if (j==5) mpfr_random (op2);
- for (k=0; k<6; k++)
+ for (k=0; k<6; k++)
{
-
MPFR_CLEAR_FLAGS(op3);
if (k==0) mpfr_set_nan (op3);
if (k==1) mpfr_set_inf (op3, 1);
@@ -179,110 +179,103 @@ test4 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
/* reference call: foo(s, a, b, c) */
testfunc (ref, op1, op2, op3, rnd);
-
+
/* foo(a, a, b, c) */
mpfr_set (res, op1, rnd); /* exact operation */
testfunc (res, res, op2, op3, rnd);
-
- if (mpfr_compare (res, ref))
- {
- fprintf (stderr,
- "Error for %s(a, a, b, c) for a=%e, b=%e, c=%e\n",
- foo,
- mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
- mpfr_get_d1 (res));
- exit (1);
- }
+
+ if (mpfr_compare (res, ref))
+ {
+ printf ("Error for %s(a, a, b, c) for a=%e, b=%e, c=%e\n",
+ foo, mpfr_get_d1 (op1), mpfr_get_d1 (op2),
+ mpfr_get_d1 (op3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref),
+ mpfr_get_d1 (res));
+ exit (1);
+ }
/* foo(b, a, b, c) */
mpfr_set (res, op2, rnd);
testfunc (res, op1, res, op3, rnd);
- if (mpfr_compare (res, ref))
- {
- fprintf (stderr,
- "Error for %s(b, a, b, c) for a=%e, b=%e, c=%e\n",
- foo,
- mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
- mpfr_get_d1 (res));
- exit (1);
- }
+ if (mpfr_compare (res, ref))
+ {
+ printf ("Error for %s(b, a, b, c) for a=%e, b=%e, c=%e\n",
+ foo, mpfr_get_d1 (op1), mpfr_get_d1 (op2),
+ mpfr_get_d1 (op3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref),
+ mpfr_get_d1 (res));
+ exit (1);
+ }
/* foo(c, a, b, c) */
mpfr_set (res, op3, rnd);
testfunc (res, op1, op2, res, rnd);
- if (mpfr_compare (res, ref))
- {
- fprintf (stderr,
- "Error for %s(c, a, b, c) for a=%e, b=%e, c=%e\n",
- foo,
- mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
- mpfr_get_d1 (res));
- exit (1);
- }
+ if (mpfr_compare (res, ref))
+ {
+ printf ("Error for %s(c, a, b, c) for a=%e, b=%e, c=%e\n",
+ foo, mpfr_get_d1 (op1), mpfr_get_d1 (op2),
+ mpfr_get_d1 (op3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref),
+ mpfr_get_d1 (res));
+ exit (1);
+ }
/* foo(a, a, a,c) */
- testfunc (ref, op1, op1, op3, rnd);
- mpfr_set (res, op1, rnd);
- testfunc (res, res, res, op3, rnd);
- if (mpfr_compare (res, ref))
- {
- fprintf (stderr,
- "Error for %s(a, a, a, c) for a=%e, a=%e, c=%e\n",
- foo,
- mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
- mpfr_get_d1 (res));
- exit (1);
- }
+ testfunc (ref, op1, op1, op3, rnd);
+ mpfr_set (res, op1, rnd);
+ testfunc (res, res, res, op3, rnd);
+ if (mpfr_compare (res, ref))
+ {
+ printf ("Error for %s(a, a, a, c) for a=%e, a=%e, c=%e\n",
+ foo, mpfr_get_d1 (op1), mpfr_get_d1 (op2),
+ mpfr_get_d1 (op3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref),
+ mpfr_get_d1 (res));
+ exit (1);
+ }
/* foo(a, a, b,a) */
testfunc (ref, op1, op2, op1, rnd);
mpfr_set (res, op1, rnd);
testfunc (res, res, op2, res, rnd);
- if (mpfr_compare (res, ref))
- {
- fprintf (stderr,
- "Error for %s(a, a, b, a) for a=%e, a=%e, c=%e\n",
- foo,
- mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
+ if (mpfr_compare (res, ref))
+ {
+ printf ("Error for %s(a, a, b, a) for a=%e, a=%e, c=%e\n",
+ foo, mpfr_get_d1 (op1), mpfr_get_d1 (op2),
+ mpfr_get_d1 (op3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref),
mpfr_get_d1 (res));
- exit (1);
- }
+ exit (1);
+ }
/* foo(b, a, b, b) */
testfunc (ref, op1, op2, op2, rnd);
mpfr_set (res, op2, rnd);
testfunc (res, op1, res, res, rnd);
- if (mpfr_compare (res, ref))
- {
- fprintf (stderr,
- "Error for %s(b, a, b, b) for a=%e, a=%e, c=%e\n",
- foo,
- mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
+ if (mpfr_compare (res, ref))
+ {
+ printf ("Error for %s(b, a, b, b) for a=%e, a=%e, c=%e\n",
+ foo, mpfr_get_d1 (op1), mpfr_get_d1 (op2),
+ mpfr_get_d1 (op3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref),
mpfr_get_d1 (res));
- exit (1);
- }
+ exit (1);
+ }
/* foo (a, a, a, a) */
testfunc (ref, op1, op1, op1 ,rnd);
mpfr_set (res, op1, rnd);
testfunc (res, res, res, res, rnd);
- if (mpfr_compare (res, ref))
- {
- fprintf (stderr,
- "Error for %s(a, a, a, a) for a=%e\n", foo,
+ if (mpfr_compare (res, ref))
+ {
+ printf ("Error for %s(a, a, a, a) for a=%e\n", foo,
mpfr_get_d1 (op1));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref),
mpfr_get_d1 (res));
- exit (1);
- }
+ exit (1);
+ }
}
}
}
@@ -304,7 +297,7 @@ test2ui (char *foo, mp_prec_t prec, mp_rnd_t rnd)
mpfr_t res1;
int i;
-#ifdef DEBUG
+#ifdef DEBUG
printf("checking %s\n", foo);
#endif
mpfr_init2 (ref1, prec);
@@ -324,9 +317,9 @@ test2ui (char *foo, mp_prec_t prec, mp_rnd_t rnd)
if (i%6==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
if (i%6==5) mpfr_random (ref2);
- if (i/6==0)
+ if (i/6==0)
ref3=0;
- else
+ else
{
mpn_random (c, 1);
ref3 = (unsigned int) c[0];
@@ -341,10 +334,10 @@ test2ui (char *foo, mp_prec_t prec, mp_rnd_t rnd)
if (mpfr_compare (res1, ref1))
{
- fprintf (stderr, "Error for %s(a, a, c) for a=%e c=%u\n", foo,
- mpfr_get_d1 (ref2), ref3);
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (res1));
+ printf ("Error for %s(a, a, c) for a=%e c=%u\n", foo,
+ mpfr_get_d1 (ref2), ref3);
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (res1));
exit (1);
}
}
@@ -363,7 +356,7 @@ testui2 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
mpfr_t res1;
int i;
-#ifdef DEBUG
+#ifdef DEBUG
printf("checking %s\n", foo);
#endif
mpfr_init2 (ref1, prec);
@@ -393,13 +386,14 @@ testui2 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
/* foo(a, b, a) */
mpfr_set (res1, ref3, rnd); /* exact operation */
testfunc (res1, ref2, res1, rnd);
- if (mpfr_compare (res1, ref1)) {
- fprintf (stderr, "Error for %s(a, b, a) for b=%u a=%e\n", foo,
- ref2, mpfr_get_d1 (ref3));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (res1));
- exit (1);
- }
+ if (mpfr_compare (res1, ref1))
+ {
+ printf ("Error for %s(a, b, a) for b=%u a=%e\n", foo,
+ ref2, mpfr_get_d1 (ref3));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (res1));
+ exit (1);
+ }
}
mpfr_clear (ref1);
@@ -415,7 +409,7 @@ test2 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
mpfr_t res1;
int i;
-#ifdef DEBUG
+#ifdef DEBUG
printf("checking %s\n", foo);
#endif
mpfr_init2 (ref1, prec);
@@ -423,27 +417,29 @@ test2 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
mpfr_init2 (res1, prec);
mpfr_random (ref2);
- for (i=0; i<6; i++) {
- if (i==0) mpfr_set_nan (ref2);
- if (i==1) mpfr_set_inf (ref2, 1);
- if (i==2) mpfr_set_inf (ref2, -1);
- if (i==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
- if (i==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
- if (i==5) mpfr_random (ref2);
+ for (i=0; i<6; i++)
+ {
+ if (i==0) mpfr_set_nan (ref2);
+ if (i==1) mpfr_set_inf (ref2, 1);
+ if (i==2) mpfr_set_inf (ref2, -1);
+ if (i==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
+ if (i==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
+ if (i==5) mpfr_random (ref2);
- /* reference call: foo(a, b) */
- testfunc (ref1, ref2, rnd);
+ /* reference call: foo(a, b) */
+ testfunc (ref1, ref2, rnd);
- /* foo(a, a) */
- mpfr_set (res1, ref2, rnd); /* exact operation */
- testfunc (res1, res1, rnd);
- if (mpfr_compare (res1, ref1)) {
- fprintf (stderr, "Error for %s(a, a) for a=%e\n", foo, mpfr_get_d1 (ref2));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (res1));
- exit (1);
+ /* foo(a, a) */
+ mpfr_set (res1, ref2, rnd); /* exact operation */
+ testfunc (res1, res1, rnd);
+ if (mpfr_compare (res1, ref1))
+ {
+ printf ("Error for %s(a, a) for a=%e\n", foo, mpfr_get_d1 (ref2));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (res1));
+ exit (1);
+ }
}
- }
mpfr_clear (ref1);
mpfr_clear (ref2);
@@ -458,35 +454,37 @@ test2a (char *foo, mp_prec_t prec)
mpfr_t res1;
int i;
-#ifdef DEBUG
- printf("checking %s\n", foo);
+#ifdef DEBUG
+ printf ("checking %s\n", foo);
#endif
mpfr_init2 (ref1, prec);
mpfr_init2 (ref2, prec);
mpfr_init2 (res1, prec);
mpfr_random (ref2);
- for (i=0; i<6; i++) {
- if (i==0) mpfr_set_nan (ref2);
- if (i==1) mpfr_set_inf (ref2, 1);
- if (i==2) mpfr_set_inf (ref2, -1);
- if (i==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
- if (i==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
- if (i==5) mpfr_random (ref2);
-
- /* reference call: foo(a, b) */
- testfunc (ref1, ref2);
-
- /* foo(a, a) */
- mpfr_set (res1, ref2, GMP_RNDN); /* exact operation */
- testfunc (res1, res1);
- if (mpfr_compare (res1, ref1)) {
- fprintf (stderr, "Error for %s(a, a) for a=%e\n", foo, mpfr_get_d1 (ref2));
- fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (res1));
- exit (1);
+ for (i=0; i<6; i++)
+ {
+ if (i==0) mpfr_set_nan (ref2);
+ if (i==1) mpfr_set_inf (ref2, 1);
+ if (i==2) mpfr_set_inf (ref2, -1);
+ if (i==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
+ if (i==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
+ if (i==5) mpfr_random (ref2);
+
+ /* reference call: foo(a, b) */
+ testfunc (ref1, ref2);
+
+ /* foo(a, a) */
+ mpfr_set (res1, ref2, GMP_RNDN); /* exact operation */
+ testfunc (res1, res1);
+ if (mpfr_compare (res1, ref1))
+ {
+ printf ("Error for %s(a, a) for a=%e\n", foo, mpfr_get_d1 (ref2));
+ printf ("expected %e, got %e\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (res1));
+ exit (1);
+ }
}
- }
mpfr_clear (ref1);
mpfr_clear (ref2);
@@ -501,8 +499,8 @@ test3a (char *foo, mp_prec_t prec, mp_rnd_t rnd)
mpfr_t res1, res2;
int i;
-#ifdef DEBUG
- printf("checking %s\n", foo);
+#ifdef DEBUG
+ printf ("checking %s\n", foo);
#endif
mpfr_init2 (ref1, prec);
mpfr_init2 (ref2, prec);
@@ -511,37 +509,40 @@ test3a (char *foo, mp_prec_t prec, mp_rnd_t rnd)
mpfr_init2 (res2, prec);
mpfr_random (ref3);
- for (i=0; i<6; i++) {
- if (i==0) mpfr_set_nan (ref3);
- if (i==1) mpfr_set_inf (ref3, 1);
- if (i==2) mpfr_set_inf (ref3, -1);
- if (i==3) mpfr_set_d (ref3, 0.0, GMP_RNDN);
- if (i==4) mpfr_set_d (ref3, -0.0, GMP_RNDN);
- if (i==5) mpfr_random (ref3);
-
- /* reference call: foo(a, b, c) */
- testfunc (ref1, ref2, ref3, rnd);
-
- /* foo(a, b, a) */
- mpfr_set (res1, ref3, rnd); /* exact operation */
- testfunc (res1, res2, res1, rnd);
- if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2)) {
- fprintf (stderr, "Error for %s(a, b, a) for a=%e\n", foo, mpfr_get_d1 (ref3));
- fprintf (stderr, "expected (%e,%e), got (%e,%e)\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (ref2), mpfr_get_d1 (res1), mpfr_get_d1 (res2));
- exit (1);
- }
-
- /* foo(a, b, b) */
- mpfr_set (res2, ref3, rnd); /* exact operation */
- testfunc (res1, res2, res2, rnd);
- if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2)) {
- fprintf (stderr, "Error for %s(a, b, b) for b=%e\n", foo, mpfr_get_d1 (ref3));
- fprintf (stderr, "expected (%e,%e), got (%e,%e)\n", mpfr_get_d1 (ref1),
- mpfr_get_d1 (ref2), mpfr_get_d1 (res1), mpfr_get_d1 (res2));
- exit (1);
- }
- }
+ for (i=0; i<6; i++)
+ {
+ if (i==0) mpfr_set_nan (ref3);
+ if (i==1) mpfr_set_inf (ref3, 1);
+ if (i==2) mpfr_set_inf (ref3, -1);
+ if (i==3) mpfr_set_d (ref3, 0.0, GMP_RNDN);
+ if (i==4) mpfr_set_d (ref3, -0.0, GMP_RNDN);
+ if (i==5) mpfr_random (ref3);
+
+ /* reference call: foo(a, b, c) */
+ testfunc (ref1, ref2, ref3, rnd);
+
+ /* foo(a, b, a) */
+ mpfr_set (res1, ref3, rnd); /* exact operation */
+ testfunc (res1, res2, res1, rnd);
+ if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2))
+ {
+ printf ("Error for %s(a, b, a) for a=%e\n", foo, mpfr_get_d1 (ref3));
+ printf ("expected (%e,%e), got (%e,%e)\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (ref2), mpfr_get_d1 (res1), mpfr_get_d1 (res2));
+ exit (1);
+ }
+
+ /* foo(a, b, b) */
+ mpfr_set (res2, ref3, rnd); /* exact operation */
+ testfunc (res1, res2, res2, rnd);
+ if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2))
+ {
+ printf ("Error for %s(a, b, b) for b=%e\n", foo, mpfr_get_d1 (ref3));
+ printf ("expected (%e,%e), got (%e,%e)\n", mpfr_get_d1 (ref1),
+ mpfr_get_d1 (ref2), mpfr_get_d1 (res1), mpfr_get_d1 (res2));
+ exit (1);
+ }
+ }
mpfr_clear (ref1);
mpfr_clear (ref2);
diff --git a/tests/tabs.c b/tests/tabs.c
index f0845f2d1..ab571900f 100644
--- a/tests/tabs.c
+++ b/tests/tabs.c
@@ -41,7 +41,7 @@ check_inexact (void)
mpfr_init (x);
mpfr_init (y);
mpfr_init (absx);
-
+
for (p=2; p<500; p++)
{
mpfr_set_prec (x, p);
@@ -55,24 +55,25 @@ check_inexact (void)
else
mpfr_set (absx, x, GMP_RNDN);
for (q=2; q<2*p; q++)
- {
- mpfr_set_prec (y, q);
- for (rnd=0; rnd<4; rnd++)
- {
- inexact = mpfr_abs (y, x, rnd);
- cmp = mpfr_cmp (y, absx);
- if (((inexact == 0) && (cmp != 0)) ||
- ((inexact > 0) && (cmp <= 0)) ||
- ((inexact < 0) && (cmp >= 0)))
- {
- fprintf (stderr, "Wrong inexact flag: expected %d, got %d\n", cmp, inexact);
- printf ("x="); mpfr_print_binary (x); puts ("");
- printf ("absx="); mpfr_print_binary (absx); puts ("");
- printf ("y="); mpfr_print_binary (y); puts ("");
- exit (1);
- }
- }
- }
+ {
+ mpfr_set_prec (y, q);
+ for (rnd=0; rnd<4; rnd++)
+ {
+ inexact = mpfr_abs (y, x, rnd);
+ cmp = mpfr_cmp (y, absx);
+ if (((inexact == 0) && (cmp != 0)) ||
+ ((inexact > 0) && (cmp <= 0)) ||
+ ((inexact < 0) && (cmp >= 0)))
+ {
+ printf ("Wrong inexact flag: expected %d, got %d\n",
+ cmp, inexact);
+ printf ("x="); mpfr_print_binary (x); puts ("");
+ printf ("absx="); mpfr_print_binary (absx); puts ("");
+ printf ("y="); mpfr_print_binary (y); puts ("");
+ exit (1);
+ }
+ }
+ }
}
mpfr_clear (x);
@@ -83,73 +84,76 @@ check_inexact (void)
int
main (int argc, char *argv[])
{
- mpfr_t x;
- int n, k, rnd;
- double d, absd, dd;
-
- mpfr_test_init ();
-
- check_inexact ();
-
- mpfr_init2(x, 53);
-
- mpfr_set_d(x, 1.0, GMP_RNDN);
- mpfr_abs(x, x, GMP_RNDN);
- if (mpfr_get_d1 (x) != 1.0) {
- fprintf(stderr, "Error in mpfr_abs(1.0)\n"); exit(1);
- }
-
- mpfr_set_d(x, -1.0, GMP_RNDN);
- mpfr_abs(x, x, GMP_RNDN);
- if (mpfr_get_d1 (x) != 1.0) {
- fprintf(stderr, "Error in mpfr_abs(-1.0)\n"); exit(1);
- }
-
- mpfr_set_inf (x, 1);
- mpfr_abs (x, x, GMP_RNDN);
- if (!mpfr_inf_p(x) || (mpfr_sgn(x) <= 0))
- {
- fprintf (stderr, "Error in mpfr_abs(Inf).\n");
- exit (1);
- }
-
- mpfr_set_inf (x, -1);
- mpfr_abs (x, x, GMP_RNDN);
- if (!mpfr_inf_p(x) || (mpfr_sgn(x) <= 0))
- {
- fprintf (stderr, "Error in mpfr_abs(-Inf).\n");
- exit (1);
- }
-
- n = (argc==1) ? 1000000 : atoi(argv[1]);
- for (k = 1; k <= n; k++)
- {
- do
- {
- d = DBL_RAND ();
- absd = ABS(d);
- }
+ mpfr_t x;
+ int n, k, rnd;
+ double d, absd, dd;
+
+ mpfr_test_init ();
+
+ check_inexact ();
+
+ mpfr_init2(x, 53);
+
+ mpfr_set_d(x, 1.0, GMP_RNDN);
+ mpfr_abs(x, x, GMP_RNDN);
+ if (mpfr_get_d1 (x) != 1.0)
+ {
+ printf ("Error in mpfr_abs(1.0)\n");
+ exit (1);
+ }
+
+ mpfr_set_d(x, -1.0, GMP_RNDN);
+ mpfr_abs(x, x, GMP_RNDN);
+ if (mpfr_get_d1 (x) != 1.0)
+ {
+ printf ("Error in mpfr_abs(-1.0)\n");
+ exit (1);
+ }
+
+ mpfr_set_inf (x, 1);
+ mpfr_abs (x, x, GMP_RNDN);
+ if (!mpfr_inf_p(x) || (mpfr_sgn(x) <= 0))
+ {
+ printf ("Error in mpfr_abs(Inf).\n");
+ exit (1);
+ }
+
+ mpfr_set_inf (x, -1);
+ mpfr_abs (x, x, GMP_RNDN);
+ if (!mpfr_inf_p(x) || (mpfr_sgn(x) <= 0))
+ {
+ printf ("Error in mpfr_abs(-Inf).\n");
+ exit (1);
+ }
+
+ n = (argc==1) ? 1000000 : atoi(argv[1]);
+ for (k = 1; k <= n; k++)
+ {
+ do
+ {
+ d = DBL_RAND ();
+ absd = ABS(d);
+ }
#ifdef HAVE_DENORMS
- while (0);
+ while (0);
#else
- while (absd < DBL_MIN);
+ while (absd < DBL_MIN);
#endif
- rnd = randlimb () % 4;
- mpfr_set_d (x, d, 0);
- mpfr_abs (x, x, rnd);
- dd = mpfr_get_d1 (x);
- if (!Isnan(d) && (dd != absd))
- {
- fprintf(stderr,
- "Mismatch on d = %.20e\n", d);
- fprintf(stderr, "dd=%.20e\n", dd);
- mpfr_print_binary(x); puts ("");
- exit(1);
- }
- }
-
- mpfr_clear(x);
-
- tests_end_mpfr ();
- return 0;
+ rnd = randlimb () % 4;
+ mpfr_set_d (x, d, 0);
+ mpfr_abs (x, x, rnd);
+ dd = mpfr_get_d1 (x);
+ if (!Isnan(d) && (dd != absd))
+ {
+ printf ("Mismatch on d = %.20e\n", d);
+ printf ("dd=%.20e\n", dd);
+ mpfr_print_binary(x); puts ("");
+ exit (1);
+ }
+ }
+
+ mpfr_clear(x);
+
+ tests_end_mpfr ();
+ return 0;
}
diff --git a/tests/tacos.c b/tests/tacos.c
index 6314b8a8b..67d3798d3 100644
--- a/tests/tacos.c
+++ b/tests/tacos.c
@@ -45,7 +45,7 @@ main (void)
mpfr_acos (y, x, GMP_RNDN);
if (mpfr_nan_p(y) == 0)
{
- fprintf (stderr, "Error: acos(NaN) != NaN\n");
+ printf ("Error: acos(NaN) != NaN\n");
exit (1);
}
@@ -53,7 +53,7 @@ main (void)
mpfr_acos (y, x, GMP_RNDN);
if (mpfr_nan_p(y) == 0)
{
- fprintf (stderr, "Error: acos(2) != NaN\n");
+ printf ("Error: acos(2) != NaN\n");
exit (1);
}
diff --git a/tests/tadd.c b/tests/tadd.c
index b7ca2a10f..1481e08c2 100644
--- a/tests/tadd.c
+++ b/tests/tadd.c
@@ -83,13 +83,14 @@ check2a (double x, int px, double y, int py, int pz, mp_rnd_t rnd_mode,
mpfr_add(zz, xx, yy, rnd_mode);
mpfr_set_prec(xx, pz);
mpfr_set_str(xx, res, 16, GMP_RNDN);
- if (mpfr_cmp(xx, zz)) {
- printf("x=%1.20e,%d y=%1.20e,%d pz=%d,rnd=%s\n",
- x,px,y,py,pz,mpfr_print_rnd_mode(rnd_mode));
- printf("got "); mpfr_print_binary(zz); puts ("");
- printf("instead of "); mpfr_print_binary(xx); puts ("");
- exit(1);
- }
+ if (mpfr_cmp(xx, zz))
+ {
+ printf ("x=%1.20e,%d y=%1.20e,%d pz=%d,rnd=%s\n",
+ x, px, y, py, pz, mpfr_print_rnd_mode (rnd_mode));
+ printf ("got "); mpfr_print_binary(zz); puts ("");
+ printf ("instead of "); mpfr_print_binary(xx); puts ("");
+ exit (1);
+ }
mpfr_clear(xx); mpfr_clear(yy); mpfr_clear(zz);
}
@@ -111,7 +112,7 @@ check64 (void)
mpfr_set_str_raw (t, "1.0101011100001000011100111110e-1");
if (mpfr_cmp (u, t))
{
- fprintf (stderr, "mpfr_add(u, x, t) failed for prec(x)=29, prec(t)=58\n");
+ printf ("mpfr_add(u, x, t) failed for prec(x)=29, prec(t)=58\n");
printf ("expected "); mpfr_out_str (stdout, 2, 29, t, GMP_RNDN);
puts ("");
printf ("got "); mpfr_out_str (stdout, 2, 29, u, GMP_RNDN);
@@ -127,14 +128,14 @@ check64 (void)
mpfr_add (u, x, t, GMP_RNDN);
if (MPFR_MANT(u)[0] << 2)
{
- fprintf (stderr, "result not normalized for prec=2\n");
+ printf ("result not normalized for prec=2\n");
mpfr_print_binary (u); puts ("");
exit (1);
}
mpfr_set_str_raw (t, "-1.0e-1");
if (mpfr_cmp (u, t))
{
- fprintf (stderr, "mpfr_add(u, x, t) failed for prec(x)=4, prec(t)=2\n");
+ printf ("mpfr_add(u, x, t) failed for prec(x)=4, prec(t)=2\n");
printf ("expected -1.0e-1\n");
printf ("got "); mpfr_out_str (stdout, 2, 4, u, GMP_RNDN);
puts ("");
@@ -149,7 +150,7 @@ check64 (void)
mpfr_add (u, x, t, GMP_RNDN); /* should give -5/8 */
mpfr_set_str_raw (t, "-1.010e-1");
if (mpfr_cmp (u, t)) {
- fprintf (stderr, "mpfr_add(u, x, t) failed for prec(x)=8, prec(t)=4\n");
+ printf ("mpfr_add(u, x, t) failed for prec(x)=8, prec(t)=4\n");
printf ("expected -1.010e-1\n");
printf ("got "); mpfr_out_str (stdout, 2, 4, u, GMP_RNDN);
puts ("");
@@ -160,46 +161,54 @@ check64 (void)
mpfr_set_str_raw (x, "-0.11111100100000000011000011100000101101010001000111E-401");
mpfr_set_str_raw (t, "0.10110000100100000101101100011111111011101000111000101E-464");
mpfr_add (u, x, t, GMP_RNDN);
- if (mpfr_cmp (u, x)) {
- fprintf (stderr, "mpfr_add(u, x, t) failed for prec(x)=112, prec(t)=98\n");
- exit (1);
- }
+ if (mpfr_cmp (u, x))
+ {
+ printf ("mpfr_add(u, x, t) failed for prec(x)=112, prec(t)=98\n");
+ exit (1);
+ }
mpfr_set_prec (x, 92); mpfr_set_prec (t, 86); mpfr_set_prec (u, 53);
mpfr_set_d (x, -5.03525136761487735093e-74, GMP_RNDN);
mpfr_set_d (t, 8.51539046314262304109e-91, GMP_RNDN);
mpfr_add (u, x, t, GMP_RNDN);
- if (mpfr_get_d1 (u) != -5.0352513676148773509283672e-74) {
- fprintf (stderr, "mpfr_add(u, x, t) failed for prec(x)=92, prec(t)=86\n");
- exit (1);
- }
+ if (mpfr_get_d1 (u) != -5.0352513676148773509283672e-74)
+ {
+ printf ("mpfr_add(u, x, t) failed for prec(x)=92, prec(t)=86\n");
+ exit (1);
+ }
mpfr_set_prec(x, 53); mpfr_set_prec(t, 76); mpfr_set_prec(u, 76);
mpfr_set_str_raw(x, "-0.10010010001001011011110000000000001010011011011110001E-32");
mpfr_set_str_raw(t, "-0.1011000101110010000101111111011111010001110011110111100110101011110010011111");
mpfr_sub(u, x, t, GMP_RNDU);
mpfr_set_str_raw(t, "0.1011000101110010000101111111011100111111101010011011110110101011101000000100");
- if (mpfr_cmp(u,t)) {
- printf("expect "); mpfr_print_binary(t); puts ("");
- fprintf (stderr, "mpfr_add failed for precisions 53-76\n"); exit(1);
- }
+ if (mpfr_cmp(u,t))
+ {
+ printf ("expect "); mpfr_print_binary(t); puts ("");
+ printf ("mpfr_add failed for precisions 53-76\n");
+ exit (1);
+ }
mpfr_set_prec(x, 53); mpfr_set_prec(t, 108); mpfr_set_prec(u, 108);
mpfr_set_str_raw(x, "-0.10010010001001011011110000000000001010011011011110001E-32");
mpfr_set_str_raw(t, "-0.101100010111001000010111111101111101000111001111011110011010101111001001111000111011001110011000000000111111");
mpfr_sub(u, x, t, GMP_RNDU);
mpfr_set_str_raw(t, "0.101100010111001000010111111101110011111110101001101111011010101110100000001011000010101110011000000000111111");
- if (mpfr_cmp(u,t)) {
- printf("expect "); mpfr_print_binary(t); puts ("");
- fprintf(stderr, "mpfr_add failed for precisions 53-108\n"); exit(1);
- }
+ if (mpfr_cmp(u,t))
+ {
+ printf ("expect "); mpfr_print_binary(t); puts ("");
+ printf ("mpfr_add failed for precisions 53-108\n");
+ exit (1);
+ }
mpfr_set_prec(x, 97); mpfr_set_prec(t, 97); mpfr_set_prec(u, 97);
mpfr_set_str_raw(x, "0.1111101100001000000001011000110111101000001011111000100001000101010100011111110010000000000000000E-39");
mpfr_set_ui(t, 1, GMP_RNDN);
mpfr_add(u, x, t, GMP_RNDN);
mpfr_set_str_raw(x, "0.1000000000000000000000000000000000000000111110110000100000000101100011011110100000101111100010001E1");
- if (mpfr_cmp(u,x)) {
- fprintf(stderr, "mpfr_add failed for precision 97\n"); exit(1);
- }
+ if (mpfr_cmp(u,x))
+ {
+ printf ("mpfr_add failed for precision 97\n");
+ exit (1);
+ }
mpfr_set_prec(x, 128); mpfr_set_prec(t, 128); mpfr_set_prec(u, 128);
mpfr_set_str_raw(x, "0.10101011111001001010111011001000101100111101000000111111111011010100001100011101010001010111111101111010100110111111100101100010E-4");
mpfr_set(t, x, GMP_RNDN);
@@ -213,33 +222,39 @@ check64 (void)
mpfr_set_str_raw(t, "0.1111101110100110110110100010101001001000011000111000011101100101110100001110101010110E-4");
mpfr_sub(u, x, t, GMP_RNDU);
mpfr_sub(x, x, t, GMP_RNDU);
- if (mpfr_cmp(x, u) != 0) {
- printf("Error in mpfr_sub: u=x-t and x=x-t give different results\n");
- exit(1);
- }
- if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
- ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0) {
- printf("Error in mpfr_sub: result is not msb-normalized (1)\n"); exit(1);
- }
+ if (mpfr_cmp(x, u) != 0)
+ {
+ printf ("Error in mpfr_sub: u=x-t and x=x-t give different results\n");
+ exit (1);
+ }
+ if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
+ ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0)
+ {
+ printf ("Error in mpfr_sub: result is not msb-normalized (1)\n");
+ exit (1);
+ }
mpfr_set_prec(x, 65); mpfr_set_prec(t, 65); mpfr_set_prec(u, 65);
mpfr_set_str_raw(x, "0.10011010101000110101010000000011001001001110001011101011111011101E623");
mpfr_set_str_raw(t, "0.10011010101000110101010000000011001001001110001011101011111011100E623");
mpfr_sub(u, x, t, GMP_RNDU);
- if (mpfr_get_d1 (u) != 9.4349060620538533806e167) { /* 2^558 */
- printf("Error (1) in mpfr_sub\n"); exit(1);
- }
+ if (mpfr_get_d1 (u) != 9.4349060620538533806e167)
+ { /* 2^558 */
+ printf ("Error (1) in mpfr_sub\n");
+ exit (1);
+ }
mpfr_set_prec(x, 64); mpfr_set_prec(t, 64); mpfr_set_prec(u, 64);
mpfr_set_str_raw(x, "0.1000011110101111011110111111000011101011101111101101101100000100E-220");
mpfr_set_str_raw(t, "0.1000011110101111011110111111000011101011101111101101010011111101E-220");
mpfr_add(u, x, t, GMP_RNDU);
- if ((MPFR_MANT(u)[0] & 1) != 1) {
- printf("error in mpfr_add with rnd_mode=GMP_RNDU\n");
- printf("b= "); mpfr_print_binary(x); puts ("");
- printf("c= "); mpfr_print_binary(t); puts ("");
- printf("b+c="); mpfr_print_binary(u); puts ("");
- exit(1);
- }
+ if ((MPFR_MANT(u)[0] & 1) != 1)
+ {
+ printf ("error in mpfr_add with rnd_mode=GMP_RNDU\n");
+ printf ("b= "); mpfr_print_binary(x); puts ("");
+ printf ("c= "); mpfr_print_binary(t); puts ("");
+ printf ("b+c="); mpfr_print_binary(u); puts ("");
+ exit (1);
+ }
/* bug found by Norbert Mueller, 14 Sep 2000 */
mpfr_set_prec(x, 56); mpfr_set_prec(t, 83); mpfr_set_prec(u, 10);
@@ -270,10 +285,12 @@ check64 (void)
mpfr_set_str_raw(x, "0.10000000000000000000000000000000E1");
mpfr_set_str_raw(t, "0.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000110001110100000100011110000101110110011101110100110110111111011010111100100000000000000000000000000E0");
mpfr_sub(u, x, t, GMP_RNDN);
- if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
- ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0) {
- printf("Error in mpfr_sub: result is not msb-normalized (2)\n"); exit(1);
- }
+ if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
+ ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0)
+ {
+ printf ("Error in mpfr_sub: result is not msb-normalized (2)\n");
+ exit (1);
+ }
/* bug found by Nathalie Revol, 21 March 2001 */
mpfr_set_prec (x, 65);
@@ -282,11 +299,12 @@ check64 (void)
mpfr_set_str_raw (x, "0.11100100101101001100111011111111110001101001000011101001001010010E-35");
mpfr_set_str_raw (t, "0.10000000000000000000000000000000000001110010010110100110011110000E1");
mpfr_sub (u, t, x, GMP_RNDU);
- if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
- ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0) {
- fprintf(stderr, "Error in mpfr_sub: result is not msb-normalized (3)\n");
- exit (1);
- }
+ if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
+ ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0)
+ {
+ printf ("Error in mpfr_sub: result is not msb-normalized (3)\n");
+ exit (1);
+ }
/* bug found by Fabrice Rouillier, 27 Mar 2001 */
mpfr_set_prec (x, 107);
@@ -295,21 +313,23 @@ check64 (void)
mpfr_set_str_raw (x, "0.10111001001111010010001000000010111111011011011101000001001000101000000000000000000000000000000000000000000E315");
mpfr_set_str_raw (t, "0.10000000000000000000000000000000000101110100100101110110000001100101011111001000011101111100100100111011000E350");
mpfr_sub (u, x, t, GMP_RNDU);
- if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
- ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0) {
- fprintf(stderr, "Error in mpfr_sub: result is not msb-normalized (4)\n");
- exit (1);
- }
-
+ if ((MPFR_MANT(u)[(MPFR_PREC(u)-1)/mp_bits_per_limb] &
+ ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0)
+ {
+ printf ("Error in mpfr_sub: result is not msb-normalized (4)\n");
+ exit (1);
+ }
+
/* checks that NaN flag is correctly reset */
mpfr_set_d (t, 1.0, GMP_RNDN);
mpfr_set_d (u, 1.0, GMP_RNDN);
mpfr_set_nan (x);
mpfr_add (x, t, u, GMP_RNDN);
- if (mpfr_cmp_ui (x, 2)) {
- fprintf (stderr, "Error in mpfr_add: 1+1 gives %e\n", mpfr_get_d1 (x));
- exit (1);
- }
+ if (mpfr_cmp_ui (x, 2))
+ {
+ printf ("Error in mpfr_add: 1+1 gives %e\n", mpfr_get_d1 (x));
+ exit (1);
+ }
mpfr_clear(x); mpfr_clear(t); mpfr_clear(u);
}
@@ -330,34 +350,35 @@ check_case_1b (void)
{
mpfr_set_prec (a, prec_a);
for (prec_b = prec_a + 2; prec_b <= 64; prec_b++)
- {
- dif = prec_b - prec_a;
- mpfr_set_prec (b, prec_b);
- /* b = 1 - 2^(-prec_a) + 2^(-prec_b) */
- mpfr_set_ui (b, 1, GMP_RNDN);
- mpfr_div_2exp (b, b, dif, GMP_RNDN);
- mpfr_sub_ui (b, b, 1, GMP_RNDN);
- mpfr_div_2exp (b, b, prec_a, GMP_RNDN);
- mpfr_add_ui (b, b, 1, GMP_RNDN);
- for (prec_c = dif; prec_c <= 64; prec_c++)
- {
- /* c = 2^(-prec_a) - 2^(-prec_b) */
- mpfr_set_prec (c, prec_c);
- mpfr_set_si (c, -1, GMP_RNDN);
- mpfr_div_2exp (c, c, dif, GMP_RNDN);
- mpfr_add_ui (c, c, 1, GMP_RNDN);
- mpfr_div_2exp (c, c, prec_a, GMP_RNDN);
- mpfr_add (a, b, c, GMP_RNDN);
- if (mpfr_cmp_ui (a, 1) != 0)
- {
- fprintf (stderr, "case (1b) failed for prec_a=%u, prec_b=%u, prec_c=%u\n", prec_a, prec_b, prec_c);
- printf("b="); mpfr_print_binary(b); puts ("");
- printf("c="); mpfr_print_binary(c); puts ("");
- printf("a="); mpfr_print_binary(a); puts ("");
- exit (1);
- }
- }
- }
+ {
+ dif = prec_b - prec_a;
+ mpfr_set_prec (b, prec_b);
+ /* b = 1 - 2^(-prec_a) + 2^(-prec_b) */
+ mpfr_set_ui (b, 1, GMP_RNDN);
+ mpfr_div_2exp (b, b, dif, GMP_RNDN);
+ mpfr_sub_ui (b, b, 1, GMP_RNDN);
+ mpfr_div_2exp (b, b, prec_a, GMP_RNDN);
+ mpfr_add_ui (b, b, 1, GMP_RNDN);
+ for (prec_c = dif; prec_c <= 64; prec_c++)
+ {
+ /* c = 2^(-prec_a) - 2^(-prec_b) */
+ mpfr_set_prec (c, prec_c);
+ mpfr_set_si (c, -1, GMP_RNDN);
+ mpfr_div_2exp (c, c, dif, GMP_RNDN);
+ mpfr_add_ui (c, c, 1, GMP_RNDN);
+ mpfr_div_2exp (c, c, prec_a, GMP_RNDN);
+ mpfr_add (a, b, c, GMP_RNDN);
+ if (mpfr_cmp_ui (a, 1) != 0)
+ {
+ printf ("case (1b) failed for prec_a=%u, prec_b=%u,"
+ " prec_c=%u\n", prec_a, prec_b, prec_c);
+ printf ("b="); mpfr_print_binary(b); puts ("");
+ printf ("c="); mpfr_print_binary(c); puts ("");
+ printf ("a="); mpfr_print_binary(a); puts ("");
+ exit (1);
+ }
+ }
+ }
}
mpfr_clear (a);
@@ -385,10 +406,10 @@ check_case_2 (void)
mpfr_add(a, b, d, GMP_RNDZ); /* a = 2^901 */
if (mpfr_cmp_ui_2exp (a, 1, 901))
{
- fprintf (stderr, "b + d fails for b=2^900+2^500+2^110, d=2^900-2^500-2^110\n");
- fprintf (stderr, "expected 1.0e901, got ");
- mpfr_out_str (stderr, 2, 0, a, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("b + d fails for b=2^900+2^500+2^110, d=2^900-2^500-2^110\n");
+ printf ("expected 1.0e901, got ");
+ mpfr_out_str (stdout, 2, 0, a, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -406,9 +427,11 @@ check_same (void)
mpfr_init(x); mpfr_set_d(x, 1.0, GMP_RNDZ);
mpfr_add(x, x, x, GMP_RNDZ);
- if (mpfr_get_d1 (x) != 2.0) {
- printf("Error when all 3 operands are equal\n"); exit(1);
- }
+ if (mpfr_get_d1 (x) != 2.0)
+ {
+ printf ("Error when all 3 operands are equal\n");
+ exit (1);
+ }
mpfr_clear(x);
}
@@ -423,7 +446,7 @@ check_inexact (void)
mp_prec_t px, py, pu, pz;
int inexact, cmp;
mp_rnd_t rnd;
-
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
@@ -436,7 +459,7 @@ check_inexact (void)
mpfr_set_prec (y, 31);
if ((inexact = mpfr_add (y, x, u, GMP_RNDN)))
{
- fprintf (stderr, "Wrong inexact flag (2): expected 0, got %d\n", inexact);
+ printf ("Wrong inexact flag (2): expected 0, got %d\n", inexact);
exit (1);
}
@@ -447,7 +470,7 @@ check_inexact (void)
mpfr_set_prec (y, 28);
if ((inexact = mpfr_add (y, x, u, GMP_RNDN)))
{
- fprintf (stderr, "Wrong inexact flag (1): expected 0, got %d\n", inexact);
+ printf ("Wrong inexact flag (1): expected 0, got %d\n", inexact);
exit (1);
}
@@ -479,7 +502,7 @@ check_inexact (void)
rnd = randlimb () % 4;
if (mpfr_add (z, x, u, rnd))
{
- fprintf (stderr, "z <- x + u should be exact\n");
+ printf ("z <- x + u should be exact\n");
printf ("x="); mpfr_print_binary (x); puts ("");
printf ("u="); mpfr_print_binary (u); puts ("");
printf ("z="); mpfr_print_binary (z); puts ("");
@@ -493,8 +516,8 @@ check_inexact (void)
((inexact > 0) && (cmp <= 0)) ||
((inexact < 0) && (cmp >= 0)))
{
- fprintf (stderr, "Wrong inexact flag for rnd=%s\n",
- mpfr_print_rnd_mode(rnd));
+ printf ("Wrong inexact flag for rnd=%s\n",
+ mpfr_print_rnd_mode(rnd));
printf ("expected %d, got %d\n", cmp, inexact);
printf ("x="); mpfr_print_binary (x); puts ("");
printf ("u="); mpfr_print_binary (u); puts ("");
@@ -601,15 +624,15 @@ main (int argc, char *argv[])
1.2377342379999998e9);
check(-4.567291988483277e8, 1262857194.0, GMP_RNDN, 53, 64, 53,
8.0612799515167236e8);
- check(4.7719471752925262e7, 196089880.0, GMP_RNDN, 53, 53, 53,
+ check(4.7719471752925262e7, 196089880.0, GMP_RNDN, 53, 53, 53,
2.4380935175292528e8);
- check(4.7719471752925262e7, 196089880.0, GMP_RNDN, 53, 64, 53,
+ check(4.7719471752925262e7, 196089880.0, GMP_RNDN, 53, 64, 53,
2.4380935175292528e8);
check(-1.716113812768534e-140, 1271212614.0, GMP_RNDZ, 53, 64, 53,
1.2712126139999998e9);
check(-1.2927455200185474e-50, 1675676122.0, GMP_RNDD, 53, 64, 53,
1.6756761219999998e9);
- check53(1.22191250737771397120e+20, 948002822.0, GMP_RNDN,
+ check53(1.22191250737771397120e+20, 948002822.0, GMP_RNDN,
122191250738719408128.0);
check53(9966027674114492.0, 1780341389094537.0, GMP_RNDN,
11746369063209028.0);
@@ -691,7 +714,7 @@ main (int argc, char *argv[])
check2a(2.72046257722708717791e+243,97,-1.62158447436486437113e+243,83,96,
GMP_RNDN, "a.4cc63e002d2e8@201");
/* Checking double precision (53 bits) */
- check53(-8.22183238641455905806e-19, 7.42227178769761587878e-19, GMP_RNDD,
+ check53(-8.22183238641455905806e-19, 7.42227178769761587878e-19, GMP_RNDD,
-7.9956059871694317927e-20);
check53(5.82106394662028628236e+234, -5.21514064202368477230e+89, GMP_RNDD,
5.8210639466202855763e234);
@@ -725,7 +748,7 @@ main (int argc, char *argv[])
5.5729438093246831053e71);
check53(6.6052588496951015469e24, 4938448004894539.0, GMP_RNDU,
6.6052588546335505068e24);
- check53(1.23056185051606761523e-190, 1.64589756643433857138e-181, GMP_RNDU,
+ check53(1.23056185051606761523e-190, 1.64589756643433857138e-181, GMP_RNDU,
1.6458975676649006598e-181);
check53(2.93231171510175981584e-280, 3.26266919161341483877e-273, GMP_RNDU,
3.2626694848445867288e-273);
@@ -748,7 +771,7 @@ main (int argc, char *argv[])
check53(9007199254740992.0, -1.0, GMP_RNDN, 9007199254740991.0);
check53(9007199254740994.0, -1.0, GMP_RNDN, 9007199254740992.0);
check53(9007199254740996.0, -1.0, GMP_RNDN, 9007199254740996.0);
-
+
tests_end_mpfr ();
return 0;
}
diff --git a/tests/tagm.c b/tests/tagm.c
index 100317a35..a939276d9 100644
--- a/tests/tagm.c
+++ b/tests/tagm.c
@@ -57,12 +57,12 @@ check4 (double a, double b, mp_rnd_t rnd_mode, double res1)
mpfr_init2(ta, 53);
mpfr_init2(tb, 53);
mpfr_init2(tres, 53);
-
+
mpfr_set_d(ta, a, rnd_mode);
mpfr_set_d(tb, b, rnd_mode);
mpfr_agm(tres, ta, tb, rnd_mode);
-
+
res2 = mpfr_get_d1 (tres);
if (res1!=res2 && !(Isnan(res1) && Isnan(res2)))
@@ -92,10 +92,10 @@ check_large (void)
mpfr_set_str_raw (a, "0.1110001000111101101010101010101101001010001001001011100101111011110101111001111100E-4");
if (mpfr_cmp (agm, a))
{
- fprintf (stderr, "mpfr_agm failed for precision 82\n");
+ printf ("mpfr_agm failed for precision 82\n");
exit (1);
}
-
+
/* problem found by Damien Fischer <damien@maths.usyd.edu.au> 4 Aug 2003:
produced a division by zero exception */
mpfr_set_prec (a, 268);
@@ -128,7 +128,7 @@ slave (int N, int p)
mpfr_set_d(tb, b, GMP_RNDN);
mpfr_agm(tres, ta, tb, randlimb () % 4 );
}
- mpfr_clear(ta); mpfr_clear(ta); mpfr_clear(tres);
+ mpfr_clear(ta); mpfr_clear(ta); mpfr_clear(tres);
printf("fin\n");
}
#endif
@@ -198,7 +198,7 @@ main (int argc, char* argv[])
N = atoi (argv[1]);
for (i = 0; i < N; i++)
{
- a = DBL_RAND ();
+ a = DBL_RAND ();
b = DBL_RAND ();
check(a, b, randlimb () % 4);
}
diff --git a/tests/tasin.c b/tests/tasin.c
index 674fa035d..da1a29f95 100644
--- a/tests/tasin.c
+++ b/tests/tasin.c
@@ -47,8 +47,8 @@ main (void)
mpfr_neg (z, z, GMP_RNDN);
if (mpfr_cmp (y, z))
{
- fprintf (stderr, "sin(-1) is wrong, expected %.20e, got %.20e\n",
- mpfr_get_d1 (z), mpfr_get_d1 (y));
+ printf ("sin(-1) is wrong, expected %.20e, got %.20e\n",
+ mpfr_get_d1 (z), mpfr_get_d1 (y));
exit (1);
}
diff --git a/tests/tatan.c b/tests/tatan.c
index b36b16e8c..a9a1e8e1c 100644
--- a/tests/tatan.c
+++ b/tests/tatan.c
@@ -30,7 +30,7 @@ static void
worst_cases (void)
{
mpfr_t x, y, z;
-
+
mpfr_init2 (x, 53);
mpfr_init2 (y, 53);
mpfr_init2 (z, 53);
@@ -40,14 +40,14 @@ worst_cases (void)
mpfr_atan (z, x, GMP_RNDN);
if (mpfr_cmp (y, z))
{
- fprintf (stderr, "Error in mpfr_atan for prec=53, rnd=GMP_RNDN\n");
- fprintf (stderr, "x=");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\nexpected ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\ngot ");
- mpfr_out_str (stderr, 2, 0, z, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("Error in mpfr_atan for prec=53, rnd=GMP_RNDN\n");
+ printf ("x=");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\nexpected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\ngot ");
+ mpfr_out_str (stdout, 2, 0, z, GMP_RNDN);
+ printf ("\n");
exit (1);
}
diff --git a/tests/tcan_round.c b/tests/tcan_round.c
index b720db91d..cc21a81ed 100644
--- a/tests/tcan_round.c
+++ b/tests/tcan_round.c
@@ -39,14 +39,14 @@ main (void)
mpfr_set_str_raw (x, "-0.10010001010111000011110010111010111110000000111101100111111E663");
if (mpfr_can_round (x, 54, GMP_RNDZ, GMP_RNDZ, 53) != 0)
{
- fprintf (stderr, "Error (1) in mpfr_can_round\n");
+ printf ("Error (1) in mpfr_can_round\n");
exit (1);
}
mpfr_set_str_raw (x, "-Inf");
if (mpfr_can_round (x, 2000, GMP_RNDZ, GMP_RNDZ, 2000) != 0)
{
- fprintf (stderr, "Error (2) in mpfr_can_round\n");
+ printf ("Error (2) in mpfr_can_round\n");
exit (1);
}
@@ -54,7 +54,7 @@ main (void)
mpfr_set_str_raw (x, "0.1011001000011110000110000110001111101011000010001110011000000000");
if (mpfr_can_round (x, 65, GMP_RNDN, GMP_RNDN, 54))
{
- fprintf (stderr, "Error (3) in mpfr_can_round\n");
+ printf ("Error (3) in mpfr_can_round\n");
exit (1);
}
diff --git a/tests/tcbrt.c b/tests/tcbrt.c
index ede5f2cd1..0eb918fd2 100644
--- a/tests/tcbrt.c
+++ b/tests/tcbrt.c
@@ -41,7 +41,7 @@ main (void)
mpfr_cbrt (x, x, GMP_RNDN);
if (mpfr_get_d1 (x) != 9.43166207799662426048e-01)
{
- fprintf (stderr, "Error (1)\n");
+ printf ("Error (1)\n");
exit (1);
}
@@ -54,20 +54,20 @@ main (void)
mpfr_cbrt (x, x, r);
if (mpfr_cmp_ui (x, 1))
{
- fprintf (stderr, "Error in mpfr_cbrt for x=1, rnd=%s\ngot ",
- mpfr_print_rnd_mode (r));
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("Error in mpfr_cbrt for x=1, rnd=%s\ngot ",
+ mpfr_print_rnd_mode (r));
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
mpfr_set_si (x, -1, GMP_RNDN);
mpfr_cbrt (x, x, r);
if (mpfr_cmp_si (x, -1))
{
- fprintf (stderr, "Error in mpfr_cbrt for x=-1, rnd=%s\ngot ",
- mpfr_print_rnd_mode (r));
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("Error in mpfr_cbrt for x=-1, rnd=%s\ngot ",
+ mpfr_print_rnd_mode (r));
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -81,11 +81,11 @@ main (void)
mpfr_cbrt (x, x, GMP_RNDN);
if (mpfr_cmp_si_2exp (x, 3, i))
{
- fprintf (stderr, "Error in mpfr_cbrt for "
- "x = 27.0 * 2^(%d), rnd=%s\ngot ",
- 3*i, mpfr_print_rnd_mode (r));
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\ninstead of 3 * 2^(%d)\n", i);
+ printf ("Error in mpfr_cbrt for "
+ "x = 27.0 * 2^(%d), rnd=%s\ngot ",
+ 3*i, mpfr_print_rnd_mode (r));
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\ninstead of 3 * 2^(%d)\n", i);
exit (1);
}
}
diff --git a/tests/tcmp.c b/tests/tcmp.c
index 54d411d26..66eca4f5e 100644
--- a/tests/tcmp.c
+++ b/tests/tcmp.c
@@ -46,7 +46,7 @@ main (void)
mpfr_set_str_raw(yy, "-0.10E0");
if (mpfr_cmp (xx, yy))
{
- fprintf (stderr, "mpfr_cmp (xx, yy) returns non-zero for prec=2\n");
+ printf ("mpfr_cmp (xx, yy) returns non-zero for prec=2\n");
exit (1);
}
@@ -57,16 +57,16 @@ main (void)
p = 0;
if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64)
{
- printf("Error (1) in mpfr_cmp2\n");
- exit(1);
+ printf ("Error (1) in mpfr_cmp2\n");
+ exit (1);
}
mpfr_set_str_raw(xx, "0.10100010001110110111000010001000010011111101000100011101000011100");
mpfr_set_str_raw(yy, "0.10100010001110110111000010001000010011111101000100011101000011011");
p = 0;
if (mpfr_cmp2(xx, yy, &p) <= 0 || p != 64)
{
- printf("Error (2) in mpfr_cmp2\n");
- exit(1);
+ printf ("Error (2) in mpfr_cmp2\n");
+ exit (1);
}
mpfr_set_prec (xx, 160); mpfr_set_prec (yy, 160);
@@ -75,91 +75,101 @@ main (void)
p = 0;
if (mpfr_cmp2 (xx, yy, &p) <= 0 || p != 144)
{
- printf("Error (3) in mpfr_cmp2\n");
- exit(1);
+ printf ("Error (3) in mpfr_cmp2\n");
+ exit (1);
}
mpfr_set_prec(xx, 53); mpfr_set_prec(yy, 200);
mpfr_set_d(xx, 1.0, 0);
mpfr_set_d(yy, 1.0, 0);
- if (mpfr_cmp(xx,yy)!=0) {
- printf("Error in mpfr_cmp: 1.0 != 1.0\n"); exit(1);
- }
+ if (mpfr_cmp(xx,yy)!=0)
+ {
+ printf ("Error in mpfr_cmp: 1.0 != 1.0\n");
+ exit (1);
+ }
mpfr_set_prec(yy, 31);
mpfr_set_d(xx, 1.0000000002, 0);
mpfr_set_d(yy, 1.0, 0);
- if (!(mpfr_cmp(xx,yy)>0)) {
- printf("Error in mpfr_cmp: not 1.0000000002 > 1.0\n"); exit(1);
- }
+ if (!(mpfr_cmp(xx,yy)>0))
+ {
+ printf ("Error in mpfr_cmp: not 1.0000000002 > 1.0\n");
+ exit (1);
+ }
mpfr_set_prec(yy, 53);
/* bug found by Gerardo Ballabio */
mpfr_set_d(xx, 0.0, GMP_RNDN);
mpfr_set_d(yy, 0.1, GMP_RNDN);
- if (mpfr_cmp(xx, yy) >= 0) {
- fprintf(stderr,
- "Error in mpfr_cmp(0.0, 0.1), gives %d\n", mpfr_cmp(xx, yy));
- exit(1);
- }
+ if (mpfr_cmp(xx, yy) >= 0)
+ {
+ printf ("Error in mpfr_cmp(0.0, 0.1), gives %d\n", mpfr_cmp(xx, yy));
+ exit (1);
+ }
mpfr_set_inf (xx, 1);
- mpfr_set_d(yy, -23489745.0329, GMP_RNDN);
- if (mpfr_cmp(xx, yy) <= 0) {
- fprintf(stderr,
- "Error in mpfr_cmp(Infp, 23489745.0329), gives %d\n", mpfr_cmp(xx, yy));
- exit(1);
- }
+ mpfr_set_d(yy, -23489745.0329, GMP_RNDN);
+ if (mpfr_cmp(xx, yy) <= 0)
+ {
+ printf ("Error in mpfr_cmp(Infp, 23489745.0329), gives %d\n",
+ mpfr_cmp(xx, yy));
+ exit (1);
+ }
mpfr_set_inf (xx, 1);
mpfr_set_inf (yy, -1);
- if (mpfr_cmp(xx, yy) <= 0) {
- fprintf(stderr,
- "Error in mpfr_cmp(Infp, Infm), gives %d\n", mpfr_cmp(xx, yy));
- exit(1);
- }
+ if (mpfr_cmp(xx, yy) <= 0)
+ {
+ printf ("Error in mpfr_cmp(Infp, Infm), gives %d\n", mpfr_cmp(xx, yy));
+ exit (1);
+ }
mpfr_set_inf (xx, -1);
mpfr_set_inf (yy, 1);
- if (mpfr_cmp(xx, yy) >= 0) {
- fprintf(stderr,
- "Error in mpfr_cmp(Infm, Infp), gives %d\n", mpfr_cmp(xx, yy));
- exit(1);
- }
+ if (mpfr_cmp(xx, yy) >= 0)
+ {
+ printf ("Error in mpfr_cmp(Infm, Infp), gives %d\n", mpfr_cmp(xx, yy));
+ exit (1);
+ }
mpfr_set_inf (xx, 1);
mpfr_set_inf (yy, 1);
- if (mpfr_cmp(xx, yy) != 0) {
- fprintf(stderr,
- "Error in mpfr_cmp(Infp, Infp), gives %d\n", mpfr_cmp(xx, yy));
- exit(1);
- }
+ if (mpfr_cmp(xx, yy) != 0)
+ {
+ printf ("Error in mpfr_cmp(Infp, Infp), gives %d\n", mpfr_cmp(xx, yy));
+ exit (1);
+ }
mpfr_set_inf (xx, -1);
mpfr_set_inf (yy, -1);
- if (mpfr_cmp(xx, yy) != 0) {
- fprintf(stderr,
- "Error in mpfr_cmp(Infm, Infm), gives %d\n", mpfr_cmp(xx, yy));
- exit(1);
- }
+ if (mpfr_cmp(xx, yy) != 0)
+ {
+ printf ("Error in mpfr_cmp(Infm, Infm), gives %d\n", mpfr_cmp(xx, yy));
+ exit (1);
+ }
mpfr_set_inf (xx, -1);
- mpfr_set_d(yy, 2346.09234, GMP_RNDN);
- if (mpfr_cmp(xx, yy) >= 0) {
- fprintf(stderr,
- "Error in mpfr_cmp(Infm, 2346.09234), gives %d\n", mpfr_cmp(xx, yy));
- exit(1);
- }
+ mpfr_set_d(yy, 2346.09234, GMP_RNDN);
+ if (mpfr_cmp(xx, yy) >= 0)
+ {
+ printf ("Error in mpfr_cmp(Infm, 2346.09234), gives %d\n",
+ mpfr_cmp(xx, yy));
+ exit (1);
+ }
mpfr_set_d (xx, 0.0, GMP_RNDN);
mpfr_set_d (yy, 1.0, GMP_RNDN);
- if ((i = mpfr_cmp3 (xx, yy, 1)) >= 0) {
- fprintf (stderr, "Error: mpfr_cmp3 (0, 1, 1) gives %d instead of a negative value\n", i);
- exit (1);
- }
- if ((i = mpfr_cmp3 (xx, yy, -1)) <= 0) {
- fprintf (stderr, "Error: mpfr_cmp3 (0, 1, -1) gives %d instead of a positive value\n", i);
- exit (1);
- }
+ if ((i = mpfr_cmp3 (xx, yy, 1)) >= 0)
+ {
+ printf ("Error: mpfr_cmp3 (0, 1, 1) gives %d instead of"
+ " a negative value\n", i);
+ exit (1);
+ }
+ if ((i = mpfr_cmp3 (xx, yy, -1)) <= 0)
+ {
+ printf ("Error: mpfr_cmp3 (0, 1, -1) gives %d instead of"
+ " a positive value\n", i);
+ exit (1);
+ }
for (i=0; i<1000000; )
{
@@ -173,8 +183,8 @@ main (void)
c = mpfr_cmp (xx,yy);
if ((c>0 && x<=y) || (c==0 && x!=y) || (c<0 && x>=y))
{
- printf ("Error in mpfr_cmp with x=%1.20e, y=%1.20e mpfr_cmp(x,y)=%d\n",
- x, y, c);
+ printf ("Error in mpfr_cmp with x=%1.20e, y=%1.20e"
+ " mpfr_cmp(x,y)=%d\n", x, y, c);
exit (1);
}
}
diff --git a/tests/tcmp2.c b/tests/tcmp2.c
index 220b1c5a3..5331263f2 100644
--- a/tests/tcmp2.c
+++ b/tests/tcmp2.c
@@ -66,26 +66,26 @@ worst_cases (void)
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 %lu instead of %u\n", l, 1);
- exit(1);
- }
+ {
+ printf ("Error in mpfr_cmp2:\nx=");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\ny=");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\ngot %lu instead of %u\n", l, 1);
+ exit (1);
+ }
mpfr_add (x, x, y, GMP_RNDN); /* x = 1 + 1/2^i */
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 %lu instead of %u\n", l, 0);
- exit(1);
- }
+ {
+ printf ("Error in mpfr_cmp2:\nx=");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\ny=");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\ngot %lu instead of %u\n", l, 0);
+ exit (1);
+ }
}
for (i=0; i<64; i++) /* |u| = i */
@@ -95,47 +95,45 @@ worst_cases (void)
set_bit (x, i + 1, 1);
set_bit (y, i + 1, 0);
for (j=0; j<64; j++) /* |v| = j */
- {
- b = randlimb () % 2;
- set_bit (x, i + j + 2, b);
- set_bit (y, i + j + 2, b);
-
+ {
+ b = randlimb () % 2;
+ set_bit (x, i + j + 2, b);
+ set_bit (y, i + j + 2, b);
for (k=0; k<64; k++)
- {
-
- if (k) set_bit (x, i + j + k + 1, 0);
- if (k) set_bit (y, i + j + k + 1, 1);
-
- set_bit (x, i + j + k + 2, 1);
- set_bit (y, i + j + k + 2, 0);
- l = 0; mpfr_cmp2 (x, y, &l);
- expected = i + j + k + 1;
- if (l != expected)
- {
- 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 %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 = 0; mpfr_cmp2 (x, y, &l);
- expected = i + j + k + 2;
- if (l != expected)
- {
- 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 %lu instead of %u\n", l, expected);
- exit(1);
- }
- }
- }
+ {
+ if (k)
+ set_bit (x, i + j + k + 1, 0);
+ if (k)
+ set_bit (y, i + j + k + 1, 1);
+ set_bit (x, i + j + k + 2, 1);
+ set_bit (y, i + j + k + 2, 0);
+ l = 0; mpfr_cmp2 (x, y, &l);
+ expected = i + j + k + 1;
+ if (l != expected)
+ {
+ printf ("Error in mpfr_cmp2:\nx=");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\ny=");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\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 = 0; mpfr_cmp2 (x, y, &l);
+ expected = i + j + k + 2;
+ if (l != expected)
+ {
+ printf ("Error in mpfr_cmp2:\nx=");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\ny=");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\ngot %lu instead of %u\n", l, expected);
+ exit (1);
+ }
+ }
+ }
}
mpfr_clear (x);
@@ -154,7 +152,7 @@ tcmp2 (double x, double y, int i)
i = 53;
else
i = (int) (__gmpfr_floor_log2 (x) - __gmpfr_floor_log2 (x - y));
- }
+ }
mpfr_init2(xx, 53); mpfr_init2(yy, 53);
mpfr_set_d (xx, x, GMP_RNDN);
mpfr_set_d (yy, y, GMP_RNDN);
@@ -163,22 +161,23 @@ tcmp2 (double x, double y, int i)
{
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);
+ printf ("Error in mpfr_cmp2 for\nx=");
+ mpfr_out_str (stdout, 2, 0, xx, GMP_RNDN);
+ printf ("\ny=");
+ mpfr_out_str (stdout, 2, 0, yy, GMP_RNDN);
+ printf ("\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 %lu instead of %u\n", j, i);
- exit(1);
- }
+ else if (j != i)
+ {
+ printf ("Error in mpfr_cmp2 for\nx=");
+ mpfr_out_str (stdout, 2, 0, xx, GMP_RNDN);
+ printf ("\ny=");
+ mpfr_out_str (stdout, 2, 0, yy, GMP_RNDN);
+ printf ("\ngot %lu instead of %u\n", j, i);
+ exit (1);
+ }
mpfr_clear(xx); mpfr_clear(yy);
}
@@ -196,80 +195,86 @@ special (void)
mpfr_set_str_raw (x, "0.10000000000000000000000000000000000001110010010110100110011110000E1");
mpfr_set_str_raw (y, "0.11100100101101001100111011111111110001101001000011101001001010010E-35");
j = 0;
- if (mpfr_cmp2 (x, y, &j) <= 0 || j != 1) {
- printf ("Error in mpfr_cmp2:\n");
- printf ("x=");
- mpfr_print_binary (x);
- puts ("");
- printf ("y=");
- mpfr_print_binary (y);
- puts ("");
- printf ("got %lu, expected 1\n", j);
- exit (1);
- }
+ if (mpfr_cmp2 (x, y, &j) <= 0 || j != 1)
+ {
+ printf ("Error in mpfr_cmp2:\n");
+ printf ("x=");
+ mpfr_print_binary (x);
+ puts ("");
+ printf ("y=");
+ mpfr_print_binary (y);
+ puts ("");
+ 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");
j = 0;
- if (mpfr_cmp2(x, y, &j) <= 0 || j != 32) {
- printf("Error in mpfr_cmp2:\n");
- printf("x="); mpfr_print_binary(x); puts ("");
- printf("y="); mpfr_print_binary(y); puts ("");
- printf("got %lu, expected 32\n", j);
- exit(1);
- }
+ if (mpfr_cmp2(x, y, &j) <= 0 || j != 32)
+ {
+ printf ("Error in mpfr_cmp2:\n");
+ printf ("x="); mpfr_print_binary(x); puts ("");
+ printf ("y="); mpfr_print_binary(y); puts ("");
+ 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");
j = 0;
- if (mpfr_cmp2(x, y, &j) <= 0 || j != 164) {
- printf("Error in mpfr_cmp2:\n");
- printf("x="); mpfr_print_binary(x); puts ("");
- printf("y="); mpfr_print_binary(y); puts ("");
- printf("got %lu, expected 164\n", j);
- exit(1);
- }
+ if (mpfr_cmp2(x, y, &j) <= 0 || j != 164)
+ {
+ printf ("Error in mpfr_cmp2:\n");
+ printf ("x="); mpfr_print_binary(x); puts ("");
+ printf ("y="); mpfr_print_binary(y); puts ("");
+ printf ("got %lu, expected 164\n", j);
+ exit (1);
+ }
/* bug found by Nathalie Revol, 29 March 2001 */
mpfr_set_prec (x, 130); mpfr_set_prec (y, 130);
mpfr_set_str_raw (x, "0.1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E2");
mpfr_set_str_raw (y, "0.1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100E2");
j = 0;
- if (mpfr_cmp2(x, y, &j) <= 0 || j != 127) {
- printf("Error in mpfr_cmp2:\n");
- printf("x="); mpfr_print_binary(x); puts ("");
- printf("y="); mpfr_print_binary(y); puts ("");
- printf("got %lu, expected 127\n", j);
- exit(1);
- }
+ if (mpfr_cmp2(x, y, &j) <= 0 || j != 127)
+ {
+ printf ("Error in mpfr_cmp2:\n");
+ printf ("x="); mpfr_print_binary(x); puts ("");
+ printf ("y="); mpfr_print_binary(y); puts ("");
+ printf ("got %lu, expected 127\n", j);
+ exit (1);
+ }
/* bug found by Nathalie Revol, 2 Apr 2001 */
mpfr_set_prec (x, 65); mpfr_set_prec (y, 65);
mpfr_set_ui (x, 5, GMP_RNDN);
mpfr_set_str_raw (y, "0.10011111111111111111111111111111111111111111111111111111111111101E3");
j = 0;
- if (mpfr_cmp2(x, y, &j) <= 0 || j != 63) {
- printf("Error in mpfr_cmp2:\n");
- printf("x="); mpfr_print_binary(x); puts ("");
- printf("y="); mpfr_print_binary(y); puts ("");
- printf("got %lu, expected 63\n", j);
- exit(1);
- }
+ if (mpfr_cmp2(x, y, &j) <= 0 || j != 63)
+ {
+ printf ("Error in mpfr_cmp2:\n");
+ printf ("x="); mpfr_print_binary(x); puts ("");
+ printf ("y="); mpfr_print_binary(y); puts ("");
+ printf ("got %lu, expected 63\n", j);
+ exit (1);
+ }
/* bug found by Nathalie Revol, 2 Apr 2001 */
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");
j = 0;
- if (mpfr_cmp2(x, y, &j) <= 0 || j != 63) {
- printf("Error in mpfr_cmp2:\n");
- printf("x="); mpfr_print_binary(x); puts ("");
- printf("y="); mpfr_print_binary(y); puts ("");
- printf("got %lu, expected 63\n", j);
- exit(1);
- }
+ if (mpfr_cmp2(x, y, &j) <= 0 || j != 63)
+ {
+ printf ("Error in mpfr_cmp2:\n");
+ printf ("x="); mpfr_print_binary(x); puts ("");
+ printf ("y="); mpfr_print_binary(y); puts ("");
+ printf ("got %lu, expected 63\n", j);
+ exit (1);
+ }
mpfr_clear(x); mpfr_clear(y);
}
diff --git a/tests/tcmp_d.c b/tests/tcmp_d.c
index 66597b32d..a91c884c6 100644
--- a/tests/tcmp_d.c
+++ b/tests/tcmp_d.c
@@ -28,26 +28,26 @@ MA 02111-1307, USA. */
int
main (void)
{
- mpfr_t x;
-
+ mpfr_t x;
+
tests_start_mpfr ();
mpfr_init2(x, 53);
mpfr_set_d(x, 2.34763465, GMP_RNDN);
- if (mpfr_cmp_d(x, 2.34763465)!=0) {
- printf("Error in mpfr_cmp_d(%1.20f,%1.20f)\n",mpfr_get_d1 (x), 2.34763465);
- mpfr_clear(x);
+ if (mpfr_cmp_d(x, 2.34763465)!=0) {
+ printf("Error in mpfr_cmp_d(%1.20f,%1.20f)\n",mpfr_get_d1 (x), 2.34763465);
+ mpfr_clear(x);
exit(1);
}
if (mpfr_cmp_d(x, 2.345)<=0) {
printf("Error in mpfr_cmp_d(%1.20f,%1.20f)\n",mpfr_get_d1 (x), 2.345);
- mpfr_clear(x);
+ mpfr_clear(x);
exit(1);
}
if (mpfr_cmp_d(x, 2.4)>=0) {
printf("Error in mpfr_cmp_d(%1.20f,%1.20f)\n",mpfr_get_d1 (x), 2.4);
- mpfr_clear(x);
+ mpfr_clear(x);
exit(1);
}
@@ -63,11 +63,11 @@ main (void)
mpfr_ui_div (x, 1, x, GMP_RNDU);
if (mpfr_cmp_d (x, 0.0) == 0)
{
- fprintf (stderr, "Error in mpfr_cmp_ui (Inf, 0)\n");
+ printf ("Error in mpfr_cmp_ui (Inf, 0)\n");
exit (1);
}
- mpfr_clear(x);
+ mpfr_clear(x);
tests_end_mpfr ();
return 0;
diff --git a/tests/tcmp_ui.c b/tests/tcmp_ui.c
index 3beb7b85e..49d4a251a 100644
--- a/tests/tcmp_ui.c
+++ b/tests/tcmp_ui.c
@@ -29,25 +29,25 @@ int
main (void)
{
mpfr_t x; unsigned long i; long s;
-
+
tests_start_mpfr ();
mpfr_init(x);
mpfr_set_ui(x, 3, GMP_RNDZ);
- if (mpfr_cmp_ui(x, i=3)!=0) {
- printf("Error in mpfr_cmp_ui(%1.20f,%lu)\n",mpfr_get_d1 (x), i);
- mpfr_clear(x);
+ if (mpfr_cmp_ui(x, i=3)!=0) {
+ printf("Error in mpfr_cmp_ui(%1.20f,%lu)\n",mpfr_get_d1 (x), i);
+ mpfr_clear(x);
exit(1);
}
if (mpfr_cmp_ui(x, i=2)<=0) {
printf("Error in mpfr_cmp_ui(%1.20f,%lu)\n",mpfr_get_d1 (x), i);
- mpfr_clear(x);
+ mpfr_clear(x);
exit(1);
}
if (mpfr_cmp_ui(x, i=4)>=0) {
printf("Error in mpfr_cmp_ui(%1.20f,%lu)\n",mpfr_get_d1 (x), i);
- mpfr_clear(x);
+ mpfr_clear(x);
exit(1);
}
mpfr_set_ui (x, 0, GMP_RNDZ);
@@ -61,17 +61,17 @@ main (void)
mpfr_set_si(x, -3, GMP_RNDZ);
if (mpfr_cmp_si(x, s=-3)!=0) {
printf("Error in mpfr_cmp_si(%1.20f,%ld)\n",mpfr_get_d1 (x), s);
- mpfr_clear(x);
+ mpfr_clear(x);
exit(1);
}
if (mpfr_cmp_si(x, s=-4)<=0) {
printf("Error in mpfr_cmp_si(%1.20f,%ld)\n",mpfr_get_d1 (x), s);
- mpfr_clear(x);
+ mpfr_clear(x);
exit(1);
}
if (mpfr_cmp_si(x, s=1)>=0) {
printf("Error in mpfr_cmp_si(%1.20f,%ld)\n",mpfr_get_d1 (x), s);
- mpfr_clear(x);
+ mpfr_clear(x);
exit(1);
}
@@ -79,11 +79,11 @@ main (void)
mpfr_ui_div (x, 1, x, GMP_RNDU);
if (mpfr_cmp_ui (x, 0) == 0)
{
- fprintf (stderr, "Error in mpfr_cmp_ui (Inf, 0)\n");
+ printf ("Error in mpfr_cmp_ui (Inf, 0)\n");
exit (1);
}
- mpfr_clear(x);
+ mpfr_clear(x);
tests_end_mpfr ();
return 0;
diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c
index 587f59867..f8f990221 100644
--- a/tests/tconst_log2.c
+++ b/tests/tconst_log2.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_const_log2.
-Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -52,13 +52,13 @@ check (mp_prec_t p0, mp_prec_t p1)
if (mpfr_cmp (x, y) && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN,
rnd, p0))
{
- fprintf (stderr, "mpfr_const_log2 fails for prec=%u, rnd=%s\n",
- (unsigned int) p0, mpfr_print_rnd_mode (rnd));
- fprintf (stderr, "expected ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\ngot ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_const_log2 fails for prec=%u, rnd=%s\n",
+ (unsigned int) p0, mpfr_print_rnd_mode (rnd));
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\ngot ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
}
@@ -90,8 +90,8 @@ main (int argc, char *argv[])
mpfr_const_log2 (x, GMP_RNDN);
if (mpfr_get_d1 (x) != 0.75)
{
- fprintf (stderr, "mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n");
- fprintf (stderr, "expected 0.75, got %f\n", mpfr_get_d1 (x));
+ printf ("mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n"
+ "expected 0.75, got %f\n", mpfr_get_d1 (x));
exit (1);
}
@@ -103,12 +103,12 @@ main (int argc, char *argv[])
mpfr_out_str (stdout, 10, 0, x, rnd);
puts ("");
}
-
+
mpfr_set_prec (x, 53);
mpfr_const_log2 (x, rnd);
if (mpfr_get_d1 (x) != 6.9314718055994530941e-1)
{
- fprintf (stderr, "mpfr_const_log2 failed for prec=53\n");
+ printf ("mpfr_const_log2 failed for prec=53\n");
exit (1);
}
diff --git a/tests/tconst_pi.c b/tests/tconst_pi.c
index 54ccb6dc6..95c3df84c 100644
--- a/tests/tconst_pi.c
+++ b/tests/tconst_pi.c
@@ -59,7 +59,7 @@ main (int argc, char *argv[])
}
else if (mpfr_get_d1 (x) != 3.141592653589793116)
{
- fprintf (stderr, "mpfr_const_pi failed for prec=53\n");
+ printf ("mpfr_const_pi failed for prec=53\n");
exit (1);
}
mpfr_clear (x);
diff --git a/tests/tcos.c b/tests/tcos.c
index 866454815..b47ea9e93 100644
--- a/tests/tcos.c
+++ b/tests/tcos.c
@@ -37,10 +37,10 @@ check53 (double x, double cos_x, mp_rnd_t rnd_mode)
mpfr_cos (c, xx, rnd_mode);
if (mpfr_get_d1 (c) != cos_x && !(Isnan(cos_x) && mpfr_nan_p(c)))
{
- fprintf (stderr, "mpfr_cos failed for x=%1.20e, rnd=%s\n", x,
- mpfr_print_rnd_mode (rnd_mode));
- fprintf (stderr, "mpfr_cos gives cos(x)=%1.20e, expected %1.20e\n",
- mpfr_get_d1 (c), cos_x);
+ printf ("mpfr_cos failed for x=%1.20e, rnd=%s\n", x,
+ mpfr_print_rnd_mode (rnd_mode));
+ printf ("mpfr_cos gives cos(x)=%1.20e, expected %1.20e\n",
+ mpfr_get_d1 (c), cos_x);
exit (1);
}
mpfr_clear (xx);
@@ -62,7 +62,7 @@ check_nans (void)
mpfr_cos (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
- fprintf (stderr, "Error: cos(NaN) != NaN\n");
+ printf ("Error: cos(NaN) != NaN\n");
exit (1);
}
@@ -70,7 +70,7 @@ check_nans (void)
mpfr_cos (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
- fprintf (stderr, "Error: cos(Inf) != NaN\n");
+ printf ("Error: cos(Inf) != NaN\n");
exit (1);
}
@@ -78,7 +78,7 @@ check_nans (void)
mpfr_cos (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
- fprintf (stderr, "Error: cos(-Inf) != NaN\n");
+ printf ("Error: cos(-Inf) != NaN\n");
exit (1);
}
@@ -110,7 +110,7 @@ main (int argc, char *argv[])
mpfr_set_str_raw (x, "1.10111100010101011110101010100e-1");
if (mpfr_cmp (y, x))
{
- fprintf (stderr, "Error for prec=30, rnd=GMP_RNDU\n");
+ printf ("Error for prec=30, rnd=GMP_RNDU\n");
printf ("expected "); mpfr_print_binary (x); puts ("");
printf (" got "); mpfr_print_binary (y); puts ("");
exit (1);
@@ -123,7 +123,7 @@ main (int argc, char *argv[])
mpfr_set_str_raw (x, "1.1111011111110010001001001011100111101110100010000010010011e-1");
if (mpfr_cmp (y, x))
{
- fprintf (stderr, "Error for prec=59, rnd=GMP_RNDU\n");
+ printf ("Error for prec=59, rnd=GMP_RNDU\n");
printf ("expected "); mpfr_print_binary (x); puts ("");
printf (" got "); mpfr_print_binary (y); puts ("");
exit (1);
@@ -136,7 +136,7 @@ main (int argc, char *argv[])
mpfr_set_str_raw (x, "1.1100e-1");
if (mpfr_cmp (y, x))
{
- fprintf (stderr, "Error for x=1.1100e-2, rnd=GMP_RNDD\n");
+ printf ("Error for x=1.1100e-2, rnd=GMP_RNDD\n");
printf ("expected 1.1100e-1, got "); mpfr_print_binary (y); puts ("");
exit (1);
}
diff --git a/tests/tdiv.c b/tests/tdiv.c
index efcac7d16..7f1c71da8 100644
--- a/tests/tdiv.c
+++ b/tests/tdiv.c
@@ -67,16 +67,17 @@ check24 (float N, float D, mp_rnd_t rnd_mode, float Q)
mpfr_set_d(d, D, rnd_mode);
mpfr_div(q, n, d, rnd_mode);
Q2 = mpfr_get_d1 (q);
- if (Q!=Q2) {
- printf("mpfr_div failed for n=%1.10e, d=%1.10e, prec=24, rnd_mode=%s\n",
- N, D, mpfr_print_rnd_mode(rnd_mode));
- printf("expected quotient is %1.10e, got %1.10e\n", Q, Q2);
- exit(1);
- }
- mpfr_clear(q); mpfr_clear(n); mpfr_clear(d);
+ if (Q!=Q2)
+ {
+ printf ("mpfr_div failed for n=%1.10e, d=%1.10e, prec=24, rnd_mode=%s\n",
+ N, D, mpfr_print_rnd_mode(rnd_mode));
+ printf ("expected quotient is %1.10e, got %1.10e\n", Q, Q2);
+ exit (1);
+ }
+ mpfr_clear(q); mpfr_clear(n); mpfr_clear(d);
}
-/* the following examples come from the paper "Number-theoretic Test
+/* the following examples come from the paper "Number-theoretic Test
Generation for Directed Rounding" from Michael Parks, Table 2 */
static void
check_float(void)
@@ -134,8 +135,8 @@ static void
check_convergence (void)
{
mpfr_t x, y; int i, j;
-
- mpfr_init2(x, 130);
+
+ mpfr_init2(x, 130);
mpfr_set_str_raw(x, "0.1011111101011010101000001010011111101000011100011101010011111011000011001010000000111100100111110011001010110100100001001000111001E6944");
mpfr_init2(y, 130);
mpfr_set_ui(y, 5, GMP_RNDN);
@@ -147,28 +148,32 @@ check_convergence (void)
mpfr_set_str_raw(y, "0.1E585");
mpfr_div(x, x, y, GMP_RNDN);
mpfr_set_str_raw(y, "0.10010010011011010100101001010111100000101110010010101E-529");
- if (mpfr_cmp(x, y)) {
- fprintf(stderr, "Error in mpfr_div for prec=64, rnd=GMP_RNDN\n");
- printf("got "); mpfr_print_binary(x); puts ("");
- printf("instead of "); mpfr_print_binary(y); puts ("");
- exit(1);
- }
-
- for (i=32; i<=64; i+=32) {
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error in mpfr_div for prec=64, rnd=GMP_RNDN\n");
+ printf ("got "); mpfr_print_binary(x); puts ("");
+ printf ("instead of "); mpfr_print_binary(y); puts ("");
+ exit(1);
+ }
+
+ for (i=32; i<=64; i+=32)
+ {
mpfr_set_prec(x, i);
mpfr_set_prec(y, i);
mpfr_set_d(x, 1.0, GMP_RNDN);
- for (j=0;j<4;j++) {
- mpfr_set_d(y, 1.0, GMP_RNDN);
- mpfr_div(y, x, y, j);
- if (mpfr_cmp_ui(y, 1)) {
- fprintf(stderr, "mpfr_div failed for x=1.0, y=1.0, prec=%u rnd=%s\n",
- i, mpfr_print_rnd_mode(j));
- printf("got "); mpfr_print_binary(y); puts ("");
- exit(1);
- }
- }
- }
+ for (j=0;j<4;j++)
+ {
+ mpfr_set_d(y, 1.0, GMP_RNDN);
+ mpfr_div(y, x, y, j);
+ if (mpfr_cmp_ui(y, 1))
+ {
+ printf ("mpfr_div failed for x=1.0, y=1.0, prec=%u rnd=%s\n",
+ i, mpfr_print_rnd_mode(j));
+ printf ("got "); mpfr_print_binary(y); puts ("");
+ exit (1);
+ }
+ }
+ }
mpfr_clear(x); mpfr_clear(y);
}
@@ -178,18 +183,18 @@ check_convergence (void)
static void
check_lowr (void)
{
- mpfr_t x, y, z, z2, z3, tmp;
- int k, c;
-
+ mpfr_t x, y, z, z2, z3, tmp;
+ int k, c;
+
mpfr_init2 (x, 1000);
mpfr_init2 (y, 100);
mpfr_init2 (tmp, 850);
mpfr_init2 (z, 10);
mpfr_init2 (z2, 10);
- mpfr_init2 (z3, 50);
+ mpfr_init2 (z3, 50);
- for (k = 1; k < KMAX; k++)
+ for (k = 1; k < KMAX; k++)
{
do
{
@@ -205,18 +210,18 @@ check_lowr (void)
c = mpfr_div (z2, x, tmp, GMP_RNDN);
if (c || mpfr_cmp(z2, z))
- {
- fprintf(stderr, "Error in mpfr_div rnd=GMP_RNDN\n");
- printf("Dividing ");
- printf("got "); mpfr_print_binary(z2); puts ("");
- printf("instead of "); mpfr_print_binary(z); puts ("");
- printf("inex flag = %d\n", c);
- exit(1);
- }
+ {
+ printf ("Error in mpfr_div rnd=GMP_RNDN\n");
+ printf ("Dividing ");
+ printf ("got "); mpfr_print_binary(z2); puts ("");
+ printf ("instead of "); mpfr_print_binary(z); puts ("");
+ printf ("inex flag = %d\n", c);
+ exit (1);
+ }
}
- mpfr_set_prec(z2, 9);
- for (k = 1; k < KMAX; k++)
+ mpfr_set_prec(z2, 9);
+ for (k = 1; k < KMAX; k++)
{
mpfr_random (z);
do
@@ -224,55 +229,54 @@ check_lowr (void)
mpfr_random (tmp);
}
while (mpfr_cmp_ui (tmp, 0) == 0);
- mpfr_mul (x, z, tmp, GMP_RNDN);
- c = mpfr_div (z2, x, tmp, GMP_RNDN);
+ mpfr_mul (x, z, tmp, GMP_RNDN);
+ c = mpfr_div (z2, x, tmp, GMP_RNDN);
if ((mpfr_cmp (z2, z) == 0 && c) || c == -1)
+ {
+ printf ("Error in mpfr_div rnd=GMP_RNDN\n");
+ printf ("Dividing ");
+ printf ("got "); mpfr_print_binary(z2); puts ("");
+ printf ("instead of "); mpfr_print_binary(z); puts ("");
+ printf ("inex flag = %d\n", c);
+ exit (1);
+ }
+ else if (c == 2)
{
- fprintf(stderr, "Error in mpfr_div rnd=GMP_RNDN\n");
- printf("Dividing ");
- printf("got "); mpfr_print_binary(z2); puts ("");
- printf("instead of "); mpfr_print_binary(z); puts ("");
- printf("inex flag = %d\n", c);
- exit(1);
- }
- else if (c == 2)
- {
- mpfr_add_one_ulp(z, GMP_RNDN);
- if (mpfr_cmp(z2, z))
- {
- fprintf(stderr, "Error in mpfr_div [even rnd?] rnd=GMP_RNDN\n");
- printf("Dividing ");
- printf("got "); mpfr_print_binary(z2); puts ("");
- printf("instead of "); mpfr_print_binary(z); puts ("");
- printf("inex flag = %d\n", 1);
- exit(1);
- }
- }
+ mpfr_add_one_ulp(z, GMP_RNDN);
+ if (mpfr_cmp(z2, z))
+ {
+ printf ("Error in mpfr_div [even rnd?] rnd=GMP_RNDN\n");
+ printf ("Dividing ");
+ printf ("got "); mpfr_print_binary(z2); puts ("");
+ printf ("instead of "); mpfr_print_binary(z); puts ("");
+ printf ("inex flag = %d\n", 1);
+ exit (1);
+ }
+ }
else if (c == -2)
- {
- mpfr_sub_one_ulp(z, GMP_RNDN);
- if (mpfr_cmp(z2, z))
- {
- fprintf(stderr, "Error in mpfr_div [even rnd?] rnd=GMP_RNDN\n");
- printf("Dividing ");
- printf("got "); mpfr_print_binary(z2); puts ("");
- printf("instead of "); mpfr_print_binary(z); puts ("");
- printf("inex flag = %d\n", 1);
- exit(1);
- }
- }
+ {
+ mpfr_sub_one_ulp(z, GMP_RNDN);
+ if (mpfr_cmp(z2, z))
+ {
+ printf ("Error in mpfr_div [even rnd?] rnd=GMP_RNDN\n");
+ printf ("Dividing ");
+ printf ("got "); mpfr_print_binary(z2); puts ("");
+ printf ("instead of "); mpfr_print_binary(z); puts ("");
+ printf ("inex flag = %d\n", 1);
+ exit (1);
+ }
+ }
}
-
- mpfr_set_prec(x, 1000);
- mpfr_set_prec(y, 100);
- mpfr_set_prec(tmp, 850);
- mpfr_set_prec(z, 10);
+ mpfr_set_prec(x, 1000);
+ mpfr_set_prec(y, 100);
+ mpfr_set_prec(tmp, 850);
+ mpfr_set_prec(z, 10);
mpfr_set_prec(z2, 10);
/* almost exact divisions */
- for (k = 1; k < KMAX; k++)
+ for (k = 1; k < KMAX; k++)
{
do
{
@@ -284,35 +288,35 @@ check_lowr (void)
mpfr_random (tmp);
}
while (mpfr_cmp_ui (tmp, 0) == 0);
- mpfr_mul(x, z, tmp, GMP_RNDN);
- mpfr_set(y, tmp, GMP_RNDD);
- mpfr_add_one_ulp(x, GMP_RNDN);
+ mpfr_mul(x, z, tmp, GMP_RNDN);
+ mpfr_set(y, tmp, GMP_RNDD);
+ mpfr_add_one_ulp(x, GMP_RNDN);
- c = mpfr_div(z2, x, y, GMP_RNDD);
- mpfr_div(z3, x, y, GMP_RNDD);
- mpfr_set(z, z3, GMP_RNDD);
+ c = mpfr_div(z2, x, y, GMP_RNDD);
+ mpfr_div(z3, x, y, GMP_RNDD);
+ mpfr_set(z, z3, GMP_RNDD);
if (c != -1 || mpfr_cmp(z2, z))
- {
- fprintf(stderr, "Error in mpfr_div rnd=GMP_RNDD\n");
- printf("got "); mpfr_print_binary(z2); puts ("");
- printf("instead of "); mpfr_print_binary(z); puts ("");
- printf("inex flag = %d\n", c);
- exit(1);
- }
+ {
+ printf ("Error in mpfr_div rnd=GMP_RNDD\n");
+ printf ("got "); mpfr_print_binary(z2); puts ("");
+ printf ("instead of "); mpfr_print_binary(z); puts ("");
+ printf ("inex flag = %d\n", c);
+ exit (1);
+ }
- mpfr_set(y, tmp, GMP_RNDU);
- c = mpfr_div(z2, x, y, GMP_RNDU);
- mpfr_div(z3, x, y, GMP_RNDU);
- mpfr_set(z, z3, GMP_RNDU);
+ mpfr_set(y, tmp, GMP_RNDU);
+ c = mpfr_div(z2, x, y, GMP_RNDU);
+ mpfr_div(z3, x, y, GMP_RNDU);
+ mpfr_set(z, z3, GMP_RNDU);
if (c != 1 || mpfr_cmp(z2, z))
- {
- fprintf(stderr, "Error in mpfr_div rnd=GMP_RNDU\n");
- printf("got "); mpfr_print_binary(z2); puts ("");
- printf("instead of "); mpfr_print_binary(z); puts ("");
- printf("inex flag = %d\n", c);
- exit(1);
- }
+ {
+ printf ("Error in mpfr_div rnd=GMP_RNDU\n");
+ printf ("got "); mpfr_print_binary(z2); puts ("");
+ printf ("instead of "); mpfr_print_binary(z); puts ("");
+ printf ("inex flag = %d\n", c);
+ exit (1);
+ }
}
mpfr_clear (x);
@@ -332,7 +336,7 @@ check_inexact (void)
mp_prec_t px, py, pu;
int inexact, cmp;
mp_rnd_t rnd;
-
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
@@ -345,21 +349,21 @@ check_inexact (void)
mpfr_set_prec (y, 28);
if ((inexact = mpfr_div (y, x, u, GMP_RNDN) >= 0))
{
- fprintf (stderr, "Wrong inexact flag (1): expected -1, got %d\n",
- inexact);
+ printf ("Wrong inexact flag (1): expected -1, got %d\n",
+ inexact);
exit (1);
}
mpfr_set_prec (x, 129);
- mpfr_set_str_raw (x, "0.111110101111001100000101011100101100110011011101010001000110110101100101000010000001110110100001101010001010100010001111001101010E-2");
+ mpfr_set_str_raw (x, "0.111110101111001100000101011100101100110011011101010001000110110101100101000010000001110110100001101010001010100010001111001101010E-2");
mpfr_set_prec (u, 15);
mpfr_set_str_raw (u, "0.101101000001100E-1");
mpfr_set_prec (y, 92);
if ((inexact = mpfr_div (y, x, u, GMP_RNDN) <= 0))
{
- fprintf (stderr, "Wrong inexact flag (1): expected 1, got %d\n",
- inexact);
- mpfr_print_binary(y); puts ("");
+ printf ("Wrong inexact flag (1): expected 1, got %d\n",
+ inexact);
+ mpfr_print_binary(y); puts ("");
exit (1);
}
@@ -380,7 +384,7 @@ check_inexact (void)
inexact = mpfr_div (y, x, u, rnd);
if (mpfr_mul (z, y, u, rnd))
{
- fprintf (stderr, "z <- y * u should be exact\n");
+ printf ("z <- y * u should be exact\n");
exit (1);
}
cmp = mpfr_cmp (z, x);
@@ -388,8 +392,8 @@ check_inexact (void)
((inexact > 0) && (cmp <= 0)) ||
((inexact < 0) && (cmp >= 0)))
{
- fprintf (stderr, "Wrong inexact flag for rnd=%s\n",
- mpfr_print_rnd_mode(rnd));
+ printf ("Wrong inexact flag for rnd=%s\n",
+ mpfr_print_rnd_mode(rnd));
printf ("expected %d, got %d\n", cmp, inexact);
printf ("x="); mpfr_print_binary (x); puts ("");
printf ("u="); mpfr_print_binary (u); puts ("");
@@ -472,22 +476,22 @@ check_nan (void)
int
main (int argc, char *argv[])
{
- mpfr_t x, y, z;
+ mpfr_t x, y, z;
tests_start_mpfr ();
- check_inexact();
+ check_inexact();
mpfr_init2 (x, 64);
mpfr_init2 (y, 64);
mpfr_init2 (z, 64);
- mpfr_set_str_raw(x, "1.00100100110110101001010010101111000001011100100101010000000000E54");
- mpfr_set_str_raw(y, "1.00000000000000000000000000000000000000000000000000000000000000E584");
- mpfr_div(z, x, y, GMP_RNDU);
+ mpfr_set_str_raw(x, "1.00100100110110101001010010101111000001011100100101010000000000E54");
+ mpfr_set_str_raw(y, "1.00000000000000000000000000000000000000000000000000000000000000E584");
+ mpfr_div(z, x, y, GMP_RNDU);
check_nan ();
- check_lowr();
+ check_lowr();
check_float(); /* checks single precision */
check_convergence();
check53(0.0, 1.0, GMP_RNDZ, 0.0);
diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c
index 23cfc78de..ced6cd364 100644
--- a/tests/tdiv_ui.c
+++ b/tests/tdiv_ui.c
@@ -35,8 +35,8 @@ check (double d, unsigned long u, mp_rnd_t rnd, double e)
mpfr_init2 (x, 53);
mpfr_init2 (y, 53);
- mpfr_set_d (x, d, rnd);
- mpfr_div_ui (y, x, u, rnd);
+ mpfr_set_d (x, d, rnd);
+ mpfr_div_ui (y, x, u, rnd);
f = mpfr_get_d1 (y);
if (f != e && !(Isnan(f) && Isnan(e)))
{
@@ -72,7 +72,7 @@ special (void)
mpfr_div_ui (y, x, 123456789, GMP_RNDN);
if (mpfr_cmp_ui (y, 0))
{
- fprintf (stderr, "mpfr_div_ui gives non-zero for 0/ui\n");
+ printf ("mpfr_div_ui gives non-zero for 0/ui\n");
exit (1);
}
@@ -84,12 +84,12 @@ special (void)
mpfr_set_str_raw (x, "0.11001010100101100011101110000001100001010110101001010011011E-48");
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "Error in x/17 for x=1/16!\n");
- fprintf (stderr, "Expected ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\nGot ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("Error in x/17 for x=1/16!\n");
+ printf ("Expected ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\nGot ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -103,7 +103,7 @@ special (void)
mpfr_div_ui (y, x, 1, GMP_RNDN);
if (mpfr_get_d1 (x) != mpfr_get_d1 (y))
{
- fprintf (stderr, "division by 1.0 fails for xprec=%u, yprec=%u\n", xprec, yprec);
+ printf ("division by 1.0 fails for xprec=%u, yprec=%u\n", xprec, yprec);
printf ("expected "); mpfr_print_binary (x); puts ("");
printf ("got "); mpfr_print_binary (y); puts ("");
exit (1);
@@ -123,7 +123,7 @@ check_inexact (void)
int inexact, cmp;
unsigned long int u;
mp_rnd_t rnd;
-
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (z);
@@ -132,34 +132,38 @@ check_inexact (void)
{
mpfr_set_prec (x, px);
mpfr_random (x);
- do { u = randlimb (); } while (u == 0);
+ do
+ {
+ u = randlimb ();
+ }
+ while (u == 0);
for (py=2; py<300; py++)
- {
- mpfr_set_prec (y, py);
- mpfr_set_prec (z, py + mp_bits_per_limb);
- for (rnd=0; rnd<4; rnd++)
- {
- inexact = mpfr_div_ui (y, x, u, rnd);
- if (mpfr_mul_ui (z, y, u, rnd))
- {
- fprintf (stderr, "z <- y * u should be exact for u=%lu\n", u);
- printf ("y="); mpfr_print_binary (y); puts ("");
- printf ("z="); mpfr_print_binary (z); puts ("");
- exit (1);
- }
- cmp = mpfr_cmp (z, x);
- if (((inexact == 0) && (cmp != 0)) ||
- ((inexact > 0) && (cmp <= 0)) ||
- ((inexact < 0) && (cmp >= 0)))
- {
- fprintf (stderr, "Wrong inexact flag for u=%lu, rnd=%s\n", u,
- mpfr_print_rnd_mode(rnd));
- printf ("x="); mpfr_print_binary (x); puts ("");
- printf ("y="); mpfr_print_binary (y); puts ("");
- exit (1);
- }
- }
- }
+ {
+ mpfr_set_prec (y, py);
+ mpfr_set_prec (z, py + mp_bits_per_limb);
+ for (rnd=0; rnd<4; rnd++)
+ {
+ inexact = mpfr_div_ui (y, x, u, rnd);
+ if (mpfr_mul_ui (z, y, u, rnd))
+ {
+ printf ("z <- y * u should be exact for u=%lu\n", u);
+ printf ("y="); mpfr_print_binary (y); puts ("");
+ printf ("z="); mpfr_print_binary (z); puts ("");
+ exit (1);
+ }
+ cmp = mpfr_cmp (z, x);
+ if (((inexact == 0) && (cmp != 0)) ||
+ ((inexact > 0) && (cmp <= 0)) ||
+ ((inexact < 0) && (cmp >= 0)))
+ {
+ printf ("Wrong inexact flag for u=%lu, rnd=%s\n", u,
+ mpfr_print_rnd_mode(rnd));
+ printf ("x="); mpfr_print_binary (x); puts ("");
+ printf ("y="); mpfr_print_binary (y); puts ("");
+ exit (1);
+ }
+ }
+ }
}
mpfr_clear (x);
@@ -190,9 +194,11 @@ main (int argc, char **argv)
mpfr_set_ui(x, 3, GMP_RNDD);
mpfr_log(x, x, GMP_RNDD);
mpfr_div_ui(x, x, 5, GMP_RNDD);
- if (mpfr_get_d1 (x) != 0.21972245773362189536) {
- fprintf(stderr, "Error in mpfr_div_ui for x=ln(3), u=5\n"); exit(1);
- }
+ if (mpfr_get_d1 (x) != 0.21972245773362189536)
+ {
+ printf ("Error in mpfr_div_ui for x=ln(3), u=5\n");
+ exit (1);
+ }
mpfr_clear(x);
tests_end_mpfr ();
diff --git a/tests/teq.c b/tests/teq.c
index 13a2d9f4a..6ccae2b21 100644
--- a/tests/teq.c
+++ b/tests/teq.c
@@ -26,42 +26,50 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
#include "mpfr-test.h"
-void special _PROTO ((void));
-
static void
teq (mpfr_t x)
{
- mpfr_t y; long k, px, mx;
+ mpfr_t y;
+ long k, px, mx;
- mpfr_init2(y, MPFR_PREC(x));
+ mpfr_init2(y, MPFR_PREC(x));
- mx = (MPFR_PREC(x) - 1)/mp_bits_per_limb;
- px = mp_bits_per_limb - 2;
+ mx = (MPFR_PREC(x) - 1)/mp_bits_per_limb;
+ px = mp_bits_per_limb - 2;
for (k = 2; k < MPFR_PREC(x); k++)
{
- mpfr_set(y, x, GMP_RNDN);
-
- MPFR_MANT(y) [mx] ^= (mp_limb_t) 1 << px;
-
- if (mpfr_eq(y, x, k) ||
- !mpfr_eq(y, x, k - 1))
- {
- fprintf(stderr, "Error in eq.\n");
- printf("x = "); mpfr_print_binary(x); printf("\n");
- printf("y = "); mpfr_print_binary(y); printf("\n");
- printf("k = %ld\n", k);
- printf("mpfr_eq(y, x, k) = %d\nmpfr_eq(y, x, k - 1) = %d\n", mpfr_eq(y, x, k),mpfr_eq(y, x, k - 1));
- mpfr_clear(x); mpfr_clear(y);
- exit(-1);
- }
-
- if (px) { --px; } else { --mx; px = mp_bits_per_limb - 1; }
+ mpfr_set(y, x, GMP_RNDN);
+
+ MPFR_MANT(y) [mx] ^= (mp_limb_t) 1 << px;
+
+ if (mpfr_eq(y, x, k) ||
+ !mpfr_eq(y, x, k - 1))
+ {
+ printf ("Error in eq.\n");
+ printf ("x = "); mpfr_print_binary (x); printf ("\n");
+ printf ("y = "); mpfr_print_binary (y); printf ("\n");
+ printf ("k = %ld\n", k);
+ printf ("mpfr_eq(y, x, k) = %d\nmpfr_eq(y, x, k - 1) = %d\n",
+ mpfr_eq (y, x, k), mpfr_eq (y, x, k - 1));
+ mpfr_clear (x); mpfr_clear (y);
+ exit (1);
+ }
+
+ if (px)
+ {
+ --px;
+ }
+ else
+ {
+ --mx;
+ px = mp_bits_per_limb - 1;
+ }
}
- mpfr_clear(y);
+ mpfr_clear(y);
}
-void
+static void
special (void)
{
mpfr_t x, y, z;
@@ -86,7 +94,7 @@ special (void)
if (error)
{
- fprintf (stderr, "Error in mpfr_eq (1, 1+1e-1000)\n");
+ printf ("Error in mpfr_eq (1, 1+1e-1000)\n");
exit (1);
}
@@ -98,19 +106,19 @@ special (void)
int
main (void)
{
- int j; mpfr_t x;
+ int j; mpfr_t x;
tests_start_mpfr ();
special ();
- mpfr_init2 (x, 1000);
+ mpfr_init2 (x, 1000);
for (j=0;j<1000;j++) {
mpfr_random (x);
teq (x);
}
- mpfr_clear (x);
+ mpfr_clear (x);
tests_end_mpfr ();
return 0;
diff --git a/tests/terf.c b/tests/terf.c
index 2f5fdbaa6..5b476d863 100644
--- a/tests/terf.c
+++ b/tests/terf.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_erf.
-Copyright 2001, 2003 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
Contributed by Ludovic Meunier and Paul Zimmermann.
This file is part of the MPFR Library.
@@ -27,9 +27,7 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-test.h"
-void test_generic _PROTO ((void));
-
-void
+static void
test_generic (void)
{
unsigned int prec, err, yprec, n, p0 = 2, p1 = 100, N = 10;
@@ -101,7 +99,7 @@ main (int argc, char *argv[])
mpfr_erf (y, x, GMP_RNDN);
if (mpfr_nan_p (y) == 0)
{
- fprintf (stderr, "mpfr_erf failed for x=NaN\n");
+ printf ("mpfr_erf failed for x=NaN\n");
exit (1);
}
@@ -109,10 +107,10 @@ main (int argc, char *argv[])
mpfr_erf (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 1))
{
- fprintf (stderr, "mpfr_erf failed for x=+Inf\n");
- fprintf (stderr, "expected 1.0, got ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_erf failed for x=+Inf\n");
+ printf ("expected 1.0, got ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -120,7 +118,7 @@ main (int argc, char *argv[])
mpfr_erf (y, x, GMP_RNDN);
if (mpfr_cmp_si (y, -1))
{
- fprintf (stderr, "mpfr_erf failed for x=-Inf\n");
+ printf ("mpfr_erf failed for x=-Inf\n");
exit (1);
}
@@ -128,7 +126,7 @@ main (int argc, char *argv[])
mpfr_erf (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 0) || MPFR_SIGN(y) < 0)
{
- fprintf (stderr, "mpfr_erf failed for x=+0\n");
+ printf ("mpfr_erf failed for x=+0\n");
exit (1);
}
@@ -136,7 +134,7 @@ main (int argc, char *argv[])
mpfr_erf (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 0) || MPFR_SIGN(y) > 0)
{
- fprintf (stderr, "mpfr_erf failed for x=-0\n");
+ printf ("mpfr_erf failed for x=-0\n");
exit (1);
}
@@ -145,13 +143,13 @@ main (int argc, char *argv[])
mpfr_set_str_raw (y, "0.11010111101110110011110100111010000010000100010001011");
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "mpfr_erf failed for x=1.0, rnd=GMP_RNDN\n");
- fprintf (stderr, "expected ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\n");
- fprintf (stderr, "got ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_erf failed for x=1.0, rnd=GMP_RNDN\n");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
+ printf ("got ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -159,11 +157,11 @@ main (int argc, char *argv[])
mpfr_erf (x, x, GMP_RNDN);
if (mpfr_cmp_ui (x, 1))
{
- fprintf (stderr, "mpfr_erf failed for x=6.6, rnd=GMP_RNDN\n");
- fprintf (stderr, "expected 1\n");
- fprintf (stderr, "got ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_erf failed for x=6.6, rnd=GMP_RNDN\n");
+ printf ("expected 1\n");
+ printf ("got ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -172,13 +170,13 @@ main (int argc, char *argv[])
mpfr_set_str_raw (y, "0.11111111111111111111111111111111111111111111111111111");
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "mpfr_erf failed for x=6.6, rnd=GMP_RNDZ\n");
- fprintf (stderr, "expected ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\n");
- fprintf (stderr, "got ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_erf failed for x=6.6, rnd=GMP_RNDZ\n");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
+ printf ("got ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -187,13 +185,13 @@ main (int argc, char *argv[])
mpfr_set_str_raw (y, "0.1111111111111111111111111111111100100111110100011");
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "mpfr_erf failed for x=4.5, rnd=GMP_RNDN\n");
- fprintf (stderr, "expected ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\n");
- fprintf (stderr, "got ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_erf failed for x=4.5, rnd=GMP_RNDN\n");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
+ printf ("got ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -204,13 +202,13 @@ main (int argc, char *argv[])
mpfr_set_str_raw (y, "0.11111111111111111111111111111111111111111111111111111111111111111100111111000100111011111011010000110101111100011001101");
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "mpfr_erf failed for x=6.6, rnd=GMP_RNDN\n");
- fprintf (stderr, "expected ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\n");
- fprintf (stderr, "got ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_erf failed for x=6.6, rnd=GMP_RNDN\n");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\n");
+ printf ("got ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
diff --git a/tests/tests.c b/tests/tests.c
index 78f90b414..4b26d1ef2 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -56,7 +56,6 @@ tests_start_mpfr (void)
{
/* don't buffer, so output is not lost if a test causes a segv etc */
setbuf (stdout, NULL);
- setbuf (stderr, NULL);
tests_memory_start ();
tests_rand_start ();
@@ -145,7 +144,7 @@ mpfr_test_init ()
d = DBL_MIN;
if (2.0 * (d / 2.0) != d)
{
- fprintf (stderr, "Warning: no denormalized numbers\n");
+ printf ("Warning: no denormalized numbers\n");
exit (1);
}
#endif
@@ -161,11 +160,10 @@ mpfr_test_init ()
d += c;
if (c != d)
{
- fprintf (stderr, "Warning: IEEE 754 standard not fully supported\n");
- fprintf (stderr, " (maybe extended precision not disabled)\n");
- fprintf (stderr, " Some tests may fail\n");
+ printf ("Warning: IEEE 754 standard not fully supported\n"
+ " (maybe extended precision not disabled)\n"
+ " Some tests may fail\n");
}
-
}
diff --git a/tests/texceptions.c b/tests/texceptions.c
index 9af908d42..758522968 100644
--- a/tests/texceptions.c
+++ b/tests/texceptions.c
@@ -31,7 +31,7 @@ static void
mpfr_set_double_range (void)
{
mpfr_set_default_prec (53);
-
+
/* in double precision format, the unbiased exponent is between 0 and
2047, where 0 is used for subnormal numbers, and 2047 for special
numbers (infinities, NaN), and the bias is 1023, thus "normal" numbers
@@ -75,13 +75,13 @@ test_set_underflow (void)
inex = mpfr_set_underflow (x, i, s);
if (mpfr_cmp (x, r[j]) || inex * t[j] <= 0)
{
- fprintf (stderr, "Error in test_set_underflow, sign = %d,"
- " rnd_mode = %s\n", s, mpfr_print_rnd_mode (i));
- fprintf (stderr, "Got\n");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, ", inex = %d\ninstead of\n", inex);
- mpfr_out_str (stderr, 2, 0, r[j], GMP_RNDN);
- fprintf (stderr, ", inex = %d\n", t[j]);
+ printf ("Error in test_set_underflow, sign = %d,"
+ " rnd_mode = %s\n", s, mpfr_print_rnd_mode (i));
+ printf ("Got\n");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf (", inex = %d\ninstead of\n", inex);
+ mpfr_out_str (stdout, 2, 0, r[j], GMP_RNDN);
+ printf (", inex = %d\n", t[j]);
exit (1);
}
}
@@ -118,13 +118,13 @@ test_set_overflow (void)
inex = mpfr_set_overflow (x, i, s);
if (mpfr_cmp (x, r[j]) || inex * t[j] <= 0)
{
- fprintf (stderr, "Error in test_set_overflow, sign = %d,"
- " rnd_mode = %s\n", s, mpfr_print_rnd_mode (i));
- fprintf (stderr, "Got\n");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, ", inex = %d\ninstead of\n", inex);
- mpfr_out_str (stderr, 2, 0, r[j], GMP_RNDN);
- fprintf (stderr, ", inex = %d\n", t[j]);
+ printf ("Error in test_set_overflow, sign = %d,"
+ " rnd_mode = %s\n", s, mpfr_print_rnd_mode (i));
+ printf ("Got\n");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf (", inex = %d\ninstead of\n", inex);
+ mpfr_out_str (stdout, 2, 0, r[j], GMP_RNDN);
+ printf (", inex = %d\n", t[j]);
exit (1);
}
}
@@ -152,7 +152,7 @@ main (int argc, char *argv[])
emax = mpfr_get_emax ();
if (emin >= emax)
{
- fprintf (stderr, "Error: emin >= emax\n");
+ printf ("Error: emin >= emax\n");
exit (1);
}
@@ -162,7 +162,7 @@ main (int argc, char *argv[])
mpfr_check_range (x, 0, GMP_RNDN);
if (!mpfr_inf_p (x) || (mpfr_sgn(x) <= 0))
{
- fprintf (stderr, "Error: 2^1024 rounded to nearest should give +Inf\n");
+ printf ("Error: 2^1024 rounded to nearest should give +Inf\n");
exit (1);
}
@@ -173,7 +173,7 @@ main (int argc, char *argv[])
mpfr_check_range (x, 0, GMP_RNDD);
if (!mpfr_number_p (x))
{
- fprintf (stderr, "Error: 2^1024 rounded down should give a normal number\n");
+ printf ("Error: 2^1024 rounded down should give a normal number\n");
exit (1);
}
@@ -182,7 +182,7 @@ main (int argc, char *argv[])
mpfr_add (x, x, x, GMP_RNDN);
if (!mpfr_inf_p (x) || (mpfr_sgn(x) <= 0))
{
- fprintf (stderr, "Error: x+x rounded to nearest for x=2^1023 should give +Inf\n");
+ printf ("Error: x+x rounded to nearest for x=2^1023 should give +Inf\n");
printf ("emax = %ld\n", mpfr_get_emax ());
printf ("got "); mpfr_print_binary (x); puts ("");
exit (1);
@@ -193,7 +193,8 @@ main (int argc, char *argv[])
mpfr_add (x, x, x, GMP_RNDD);
if (!mpfr_number_p (x))
{
- fprintf (stderr, "Error: x+x rounded down for x=2^1023 should give a normal number\n");
+ printf ("Error: x+x rounded down for x=2^1023 should give"
+ " a normal number\n");
exit (1);
}
@@ -203,14 +204,15 @@ main (int argc, char *argv[])
mpfr_sub (y, y, x, GMP_RNDZ);
if (mpfr_cmp_ui (y, 0))
{
- fprintf (stderr, "Error: y-x rounded to zero should give 0 for y=3/2*2^(-1022), x=2^(-1022)\n");
+ printf ("Error: y-x rounded to zero should give 0"
+ " for y=3/2*2^(-1022), x=2^(-1022)\n");
printf ("y="); mpfr_print_binary (y); puts ("");
exit (1);
}
mpfr_clear (x);
mpfr_clear (y);
-
+
tests_end_mpfr ();
return 0;
}
diff --git a/tests/texp.c b/tests/texp.c
index 128125ee3..bd8d1c8d9 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -42,8 +42,8 @@ check3 (double d, mp_rnd_t rnd, double e)
mpfr_init2 (x, 53);
mpfr_init2 (y, 53);
- mpfr_set_d (x, d, rnd);
- mpfr_exp (y, x, rnd);
+ mpfr_set_d (x, d, rnd);
+ mpfr_exp (y, x, rnd);
f = mpfr_get_d1 (y);
if (f != e && !(Isnan(f) && Isnan(e)))
{
@@ -73,7 +73,7 @@ static int
check_large (double d, int n, mp_rnd_t rnd)
{
mpfr_t x, y;
-
+
mpfr_init2 (x, n);
mpfr_init2 (y, n);
if (d == 0.0)
@@ -120,7 +120,7 @@ check_worst_case (double X, double expx)
mpfr_exp(y, x, GMP_RNDD);
if (mpfr_get_d1 (y) != expx)
{
- fprintf(stderr, "exp(x) rounded towards -infinity is wrong\n");
+ printf ("exp(x) rounded towards -infinity is wrong\n");
exit(1);
}
mpfr_exp(x, x, GMP_RNDN);
@@ -129,7 +129,7 @@ check_worst_case (double X, double expx)
mpfr_add_one_ulp(y, GMP_RNDN);
if (mpfr_cmp(x,y))
{
- fprintf(stderr, "exp(x) rounded towards +infinity is wrong\n");
+ printf ("exp(x) rounded towards +infinity is wrong\n");
exit(1);
}
mpfr_clear(x); mpfr_clear(y);
@@ -169,12 +169,12 @@ check_worst_cases (void)
mpfr_exp3 (x, x, GMP_RNDD);
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "mpfr_exp_2 and mpfr_exp3 differ for prec=601\n");
- fprintf (stderr, "mpfr_exp_2 gives ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\nmpfr_exp_3 gives ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("mpfr_exp_2 and mpfr_exp3 differ for prec=601\n");
+ printf ("mpfr_exp_2 gives ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\nmpfr_exp_3 gives ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -242,10 +242,10 @@ check_special ()
if (mpfr_cmp (y, z))
{
- fprintf (stderr, "Error in mpfr_exp for large argument\n");
+ printf ("Error in mpfr_exp for large argument\n");
exit (1);
}
-
+
mpfr_clear (x);
mpfr_clear (y);
mpfr_clear (z);
@@ -262,7 +262,7 @@ main (int argc, char *argv[])
if (argc == 4)
{
- check_large (atof(argv[1]), atoi(argv[2]), atoi(argv[3]));
+ check_large (atof(argv[1]), atoi(argv[2]), atoi(argv[3]));
exit (0);
}
@@ -291,7 +291,7 @@ main (int argc, char *argv[])
check3(2.58165606081678085104e+01, GMP_RNDD, 1.62925781879432281494e+11);
check3(-2.36539020084338638128e+01, GMP_RNDZ, 5.33630792749924762447e-11);
check3(2.39211946135858077866e+01, GMP_RNDU, 2.44817704330214385986e+10);
- check3(-2.78190533055889162029e+01, GMP_RNDZ, 8.2858803483596879512e-13);
+ check3(-2.78190533055889162029e+01, GMP_RNDZ, 8.2858803483596879512e-13);
check3(2.64028186174889789584e+01, GMP_RNDD, 2.9281844652878973388e11);
check3(2.92086338843268329413e+01, GMP_RNDZ, 4.8433797301907177734e12);
check3(-2.46355324071459982349e+01, GMP_RNDZ, 1.9995129297760994791e-11);
@@ -301,11 +301,11 @@ main (int argc, char *argv[])
d = 7819821913254249.0 / 70368744177664.0;
check3(d, GMP_RNDN, 1.8262572323517295459e48);
check3(-3.56196340354684821250e+02, GMP_RNDN, 2.0225297096141478156e-155);
- check3(6.59678273772710895173e+02, GMP_RNDU, 3.1234469273830195529e286);
- check3(5.13772529701934331570e+02, GMP_RNDD, 1.3445427121297197752e223);
- check3(3.57430211008718345056e+02, GMP_RNDD, 1.6981197246857298443e155);
- check3(3.82001814471465536371e+02, GMP_RNDU, 7.9667300591087367805e165);
- check3(5.92396038219384422518e+02, GMP_RNDD, 1.880747529554661989e257);
+ check3(6.59678273772710895173e+02, GMP_RNDU, 3.1234469273830195529e286);
+ check3(5.13772529701934331570e+02, GMP_RNDD, 1.3445427121297197752e223);
+ check3(3.57430211008718345056e+02, GMP_RNDD, 1.6981197246857298443e155);
+ check3(3.82001814471465536371e+02, GMP_RNDU, 7.9667300591087367805e165);
+ check3(5.92396038219384422518e+02, GMP_RNDD, 1.880747529554661989e257);
check3(-5.02678550462488090034e+02, GMP_RNDU, 4.8919201895446217839e-219);
check3(5.30015757134837031117e+02, GMP_RNDD, 1.5237672861171573939e230);
check3(5.16239362447650933063e+02, GMP_RNDZ, 1.5845518406744492105e224);
diff --git a/tests/texp2.c b/tests/texp2.c
index f8f42b306..e0e7113af 100644
--- a/tests/texp2.c
+++ b/tests/texp2.c
@@ -47,7 +47,7 @@ main (int argc, char *argv[])
mpfr_exp2 (y, x, GMP_RNDU);
if (mpfr_cmp_ui (y, 16) != 0)
{
- fprintf (stderr, "Error for 2^4\n");
+ printf ("Error for 2^4\n");
exit (1);
}
@@ -57,7 +57,7 @@ main (int argc, char *argv[])
mpfr_exp2 (y, x, GMP_RNDU);
if (mpfr_cmp_ui_2exp (y, 1, -4) != 0)
{
- fprintf (stderr, "Error for 2^(-4)\n");
+ printf ("Error for 2^(-4)\n");
exit (1);
}
@@ -67,7 +67,7 @@ main (int argc, char *argv[])
mpfr_exp2 (y, x, GMP_RNDN);
if (mpfr_get_d1 (y) != 2.991959870867646566478e-231)
{
- fprintf (stderr, "Error for x=-1683977482443233/2^41\n");
+ printf ("Error for x=-1683977482443233/2^41\n");
exit (1);
}
@@ -77,7 +77,7 @@ main (int argc, char *argv[])
mpfr_exp2 (y, x, GMP_RNDN);
if(!MPFR_IS_INF(y))
{
- fprintf (stderr, "evaluation of function in INF does not return INF\n");
+ printf ("evaluation of function in INF does not return INF\n");
exit (1);
}
@@ -85,7 +85,7 @@ main (int argc, char *argv[])
mpfr_exp2 (y, x, GMP_RNDN);
if(!MPFR_IS_ZERO(y))
{
- fprintf (stderr, "evaluation of function in -INF does not return 0\n");
+ printf ("evaluation of function in -INF does not return 0\n");
exit (1);
}
@@ -93,7 +93,7 @@ main (int argc, char *argv[])
mpfr_exp2 (y, x, GMP_RNDN);
if(!MPFR_IS_NAN(y))
{
- fprintf (stderr, "evaluation of function in NaN does not return NaN\n");
+ printf ("evaluation of function in NaN does not return NaN\n");
exit (1);
}
diff --git a/tests/tfactorial.c b/tests/tfactorial.c
index 7e368c4ec..4f51ec30a 100644
--- a/tests/tfactorial.c
+++ b/tests/tfactorial.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_factorial.
-Copyright 2001 Free Software Foundation.
+Copyright 2001, 2002, 2003 Free Software Foundation.
Adapted from tarctan.c.
This file is part of the MPFR Library.
@@ -46,7 +46,7 @@ main (int argc, char *argv[])
mpfr_init (t);
mpfr_fac_ui (y, 0, GMP_RNDN);
-
+
if (mpfr_cmp_ui (y, 1))
{
printf ("mpfr_fac_ui(0) does not give 1\n");
@@ -63,7 +63,7 @@ main (int argc, char *argv[])
for (n=0; n<100; n++)
for (rnd=0; rnd<4; rnd++)
- {
+ {
inexact = mpfr_fac_ui (y, n, rnd);
err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
if (mpfr_can_round (y, err, rnd, rnd, prec))
@@ -77,7 +77,7 @@ main (int argc, char *argv[])
{
if (inexact)
{
- fprintf (stderr, "Wrong inexact flag: expected exact\n");
+ printf ("Wrong inexact flag: expected exact\n");
exit (1);
}
}
@@ -85,7 +85,7 @@ main (int argc, char *argv[])
{
if (!inexact)
{
- fprintf (stderr, "Wrong inexact flag: expected inexact\n");
+ printf ("Wrong inexact flag: expected inexact\n");
printf ("n=%u prec=%u\n", n, prec);
mpfr_print_binary(z); puts ("");
exit (1);
diff --git a/tests/tfma.c b/tests/tfma.c
index bdddb25bc..e86a7c125 100644
--- a/tests/tfma.c
+++ b/tests/tfma.c
@@ -61,7 +61,7 @@ main (int argc, char *argv[])
mpfr_set_str_raw (z, "-1.00011110100011001011001001e-1");
if (mpfr_fma (s, x, y, z, GMP_RNDN) >= 0)
{
- fprintf (stderr, "Wrong inexact flag for x=y=1-2^(-27)\n");
+ printf ("Wrong inexact flag for x=y=1-2^(-27)\n");
exit (1);
}
@@ -71,7 +71,7 @@ main (int argc, char *argv[])
mpfr_fma (s,x, y,z, GMP_RNDN);
if(!MPFR_IS_NAN(s))
{
- fprintf (stderr, "evaluation of function in x=NAN does not return NAN");
+ printf ("evaluation of function in x=NAN does not return NAN");
exit (1);
}
@@ -262,10 +262,10 @@ main (int argc, char *argv[])
mpfr_set_prec (t, prec);
for (n=0; n<N; n++)
- {
+ {
mpfr_random (x);
- mpfr_random (y);
- mpfr_random (z);
+ mpfr_random (y);
+ mpfr_random (z);
if (randlimb () % 2)
mpfr_neg (x, x, GMP_RNDN);
@@ -274,52 +274,52 @@ main (int argc, char *argv[])
if (randlimb () % 2)
mpfr_neg (z, z, GMP_RNDN);
- rnd = randlimb () % 4;
- mpfr_set_prec (slong, 2 * prec);
- if (mpfr_mul (slong, x, y, rnd))
- {
- fprintf (stderr, "x*y should be exact\n");
- exit (1);
- }
- compare = mpfr_add (t, slong, z, rnd);
- inexact = mpfr_fma (s, x, y, z, rnd);
- if (mpfr_cmp (s, t))
- {
- printf ("results differ for x=");
- mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
- printf (" y=");
- mpfr_out_str (stdout, 2, prec, y, GMP_RNDN);
- printf (" z=");
- mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
- printf (" prec=%u rnd_mode=%s\n", (unsigned) prec,
- mpfr_print_rnd_mode (rnd));
- printf ("got ");
- mpfr_out_str (stdout, 2, prec, s, GMP_RNDN);
- puts ("");
- printf ("expected ");
- mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
- puts ("");
- printf ("approx ");
- mpfr_print_binary (slong);
- puts ("");
- exit (1);
- }
- if (((inexact == 0) && (compare != 0)) ||
- ((inexact < 0) && (compare >= 0)) ||
- ((inexact > 0) && (compare <= 0)))
- {
- fprintf (stderr, "Wrong inexact flag for rnd=%s: expected %d, got %d\n",
- mpfr_print_rnd_mode (rnd), compare, inexact);
- fprintf (stderr, "x="); mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, " y="); mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, " z="); mpfr_out_str (stderr, 2, 0, z, GMP_RNDN);
- fprintf (stderr, " s="); mpfr_out_str (stderr, 2, 0, s, GMP_RNDN);
- fprintf (stderr, "\n");
- fprintf (stderr, "z=%1.20e s=%1.20e\n", mpfr_get_d1 (z),
- mpfr_get_d1 (s));
- exit (1);
- }
- }
+ rnd = randlimb () % 4;
+ mpfr_set_prec (slong, 2 * prec);
+ if (mpfr_mul (slong, x, y, rnd))
+ {
+ printf ("x*y should be exact\n");
+ exit (1);
+ }
+ compare = mpfr_add (t, slong, z, rnd);
+ inexact = mpfr_fma (s, x, y, z, rnd);
+ if (mpfr_cmp (s, t))
+ {
+ printf ("results differ for x=");
+ mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
+ printf (" y=");
+ mpfr_out_str (stdout, 2, prec, y, GMP_RNDN);
+ printf (" z=");
+ mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
+ printf (" prec=%u rnd_mode=%s\n", (unsigned int) prec,
+ mpfr_print_rnd_mode (rnd));
+ printf ("got ");
+ mpfr_out_str (stdout, 2, prec, s, GMP_RNDN);
+ puts ("");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
+ puts ("");
+ printf ("approx ");
+ mpfr_print_binary (slong);
+ puts ("");
+ exit (1);
+ }
+ if (((inexact == 0) && (compare != 0)) ||
+ ((inexact < 0) && (compare >= 0)) ||
+ ((inexact > 0) && (compare <= 0)))
+ {
+ printf ("Wrong inexact flag for rnd=%s: expected %d, got %d\n",
+ mpfr_print_rnd_mode (rnd), compare, inexact);
+ printf ("x="); mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf (" y="); mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf (" z="); mpfr_out_str (stdout, 2, 0, z, GMP_RNDN);
+ printf (" s="); mpfr_out_str (stdout, 2, 0, s, GMP_RNDN);
+ printf ("\n");
+ printf ("z=%1.20e s=%1.20e\n", mpfr_get_d1 (z),
+ mpfr_get_d1 (s));
+ exit (1);
+ }
+ }
}
mpfr_clear (t);
mpfr_clear (slong);
diff --git a/tests/tfrac.c b/tests/tfrac.c
index 1e7c88d98..7202b0d51 100644
--- a/tests/tfrac.c
+++ b/tests/tfrac.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_frac.
-Copyright 2002 Free Software Foundation.
+Copyright 2002, 2003 Free Software Foundation.
This file is part of the MPFR Library.
@@ -42,17 +42,17 @@ check0 (mpfr_ptr ip, mpfr_ptr fp, mp_prec_t prec, mp_rnd_t rnd)
if (MPFR_SIGN (ip) != MPFR_SIGN (fp))
{
- fprintf (stderr, "Internal error (1)\n");
+ printf ("Internal error (1)\n");
exit (1);
}
if (mpfr_add (sum, ip, fp, GMP_RNDZ))
{
- fprintf (stderr, "Wrong inexact flag in mpfr_add\n");
+ printf ("Wrong inexact flag in mpfr_add\n");
exit (1);
}
if (MPFR_SIGN (sum) != MPFR_SIGN (fp))
{
- fprintf (stderr, "Internal error (2)\n");
+ printf ("Internal error (2)\n");
exit (1);
}
@@ -60,23 +60,23 @@ check0 (mpfr_ptr ip, mpfr_ptr fp, mp_prec_t prec, mp_rnd_t rnd)
inex2 = mpfr_set (fp2, fp, rnd);
if (inex1 != inex2)
{
- fprintf (stderr, "Wrong inexact flag in mpfr_frac for\n");
- mpfr_out_str (stderr, 2, 0, sum, GMP_RNDN);
- fprintf (stderr, "\nGot %d instead of %d\n", inex1, inex2);
+ printf ("Wrong inexact flag in mpfr_frac for\n");
+ mpfr_out_str (stdout, 2, 0, sum, GMP_RNDN);
+ printf ("\nGot %d instead of %d\n", inex1, inex2);
exit (1);
}
if (!mpfr_number_p (dst) ||
MPFR_SIGN (dst) != MPFR_SIGN (fp2) ||
mpfr_cmp (dst, fp2))
{
- fprintf (stderr, "Error in mpfr_frac (y, x, %s) with\nx = ",
- mpfr_print_rnd_mode (rnd));
- mpfr_out_str (stderr, 2, 0, sum, GMP_RNDN);
- fprintf (stderr, "\nGot ");
- mpfr_out_str (stderr, 2, 0, dst, GMP_RNDN);
- fprintf (stderr, "\ninstead of ");
- mpfr_out_str (stderr, 2, 0, fp2, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("Error in mpfr_frac (y, x, %s) with\nx = ",
+ mpfr_print_rnd_mode (rnd));
+ mpfr_out_str (stdout, 2, 0, sum, GMP_RNDN);
+ printf ("\nGot ");
+ mpfr_out_str (stdout, 2, 0, dst, GMP_RNDN);
+ printf ("\ninstead of ");
+ mpfr_out_str (stdout, 2, 0, fp2, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -85,22 +85,22 @@ check0 (mpfr_ptr ip, mpfr_ptr fp, mp_prec_t prec, mp_rnd_t rnd)
inex1 = mpfr_frac (sum, sum, rnd);
if (inex1)
{
- fprintf (stderr, "Wrong inexact flag in mpfr_frac\n");
+ printf ("Wrong inexact flag in mpfr_frac\n");
exit (1);
}
if (!mpfr_number_p (sum) ||
MPFR_SIGN (sum) != MPFR_SIGN (fp) ||
mpfr_cmp (sum, fp))
{
- fprintf (stderr, "Error in mpfr_frac (x, x, %s) with\nx = ",
- mpfr_print_rnd_mode (rnd));
+ printf ("Error in mpfr_frac (x, x, %s) with\nx = ",
+ mpfr_print_rnd_mode (rnd));
mpfr_add (tmp, ip, fp, GMP_RNDZ);
- mpfr_out_str (stderr, 2, 0, tmp, GMP_RNDN);
- fprintf (stderr, "\nGot ");
- mpfr_out_str (stderr, 2, 0, sum, GMP_RNDN);
- fprintf (stderr, "\ninstead of ");
- mpfr_out_str (stderr, 2, 0, fp, GMP_RNDN);
- fprintf (stderr, "\n");
+ mpfr_out_str (stdout, 2, 0, tmp, GMP_RNDN);
+ printf ("\nGot ");
+ mpfr_out_str (stdout, 2, 0, sum, GMP_RNDN);
+ printf ("\ninstead of ");
+ mpfr_out_str (stdout, 2, 0, fp, GMP_RNDN);
+ printf ("\n");
exit (1);
}
}
diff --git a/tests/tgamma.c b/tests/tgamma.c
index 4d17bdff3..77fb0f530 100644
--- a/tests/tgamma.c
+++ b/tests/tgamma.c
@@ -48,8 +48,8 @@ main (void)
mpfr_gamma (y, x, GMP_RNDN);
if (mpfr_get_d (y, GMP_RNDN) != (yd = 0.96134843256452096050))
{
- fprintf (stderr, "mpfr_gamma(%1.20e) is wrong: expected %1.20e, got %1.20e\n",
- xd, yd, mpfr_get_d (y, GMP_RNDN));
+ printf ("mpfr_gamma(%1.20e) is wrong: expected %1.20e, got %1.20e\n",
+ xd, yd, mpfr_get_d (y, GMP_RNDN));
exit (1);
}
@@ -58,8 +58,8 @@ main (void)
mpfr_gamma (y, x, GMP_RNDN);
if (mpfr_get_d (y, GMP_RNDN) != (yd = 1.0502315560291053398))
{
- fprintf (stderr, "mpfr_gamma(%1.20e) is wrong: expected %1.20e, got %1.20e\n",
- xd, yd, mpfr_get_d (y, GMP_RNDN));
+ printf ("mpfr_gamma(%1.20e) is wrong: expected %1.20e, got %1.20e\n",
+ xd, yd, mpfr_get_d (y, GMP_RNDN));
exit (1);
}
diff --git a/tests/tgeneric.c b/tests/tgeneric.c
index b32c825a7..3ecd258c2 100644
--- a/tests/tgeneric.c
+++ b/tests/tgeneric.c
@@ -42,56 +42,56 @@ test_generic (int p0, int p1, int N)
yprec = prec + 10;
for (n=0; n<N; n++)
- {
+ {
#if defined(RAND_FUNCTION)
- RAND_FUNCTION (x);
+ RAND_FUNCTION (x);
#else
- mpfr_random (x);
+ mpfr_random (x);
#endif
- rnd = randlimb () % 4;
- mpfr_set_prec (y, yprec);
- compare = TEST_FUNCTION (y, x, rnd);
- if (mpfr_can_round (y, yprec, rnd, rnd, prec))
- {
- mpfr_set (t, y, rnd);
- inexact = TEST_FUNCTION (z, x, rnd);
- if (mpfr_cmp (t, z))
- {
- printf ("results differ for x=");
- mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
- printf (" prec=%u rnd_mode=%s\n", (unsigned) prec,
- mpfr_print_rnd_mode (rnd));
- printf ("got ");
- mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
- puts ("");
- printf ("expected ");
- mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
- puts ("");
- printf ("approx ");
- mpfr_print_binary (y);
- puts ("");
- exit (1);
- }
- compare2 = mpfr_cmp (t, y);
- /* if rounding to nearest, cannot know the sign of t - f(x)
- because of composed rounding: y = o(f(x)) and t = o(y) */
- if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
- compare = compare + compare2;
- else
- compare = inexact; /* cannot determine sign(t-f(x)) */
- if (((inexact == 0) && (compare != 0)) ||
- ((inexact > 0) && (compare <= 0)) ||
- ((inexact < 0) && (compare >= 0)))
- {
- fprintf (stderr, "Wrong inexact flag for rnd=%s: expected %d, got %d\n",
- mpfr_print_rnd_mode (rnd), compare, inexact);
- printf ("x="); mpfr_print_binary (x); puts ("");
- printf ("y="); mpfr_print_binary (y); puts ("");
- printf ("t="); mpfr_print_binary (t); puts ("");
- exit (1);
- }
- }
- }
+ rnd = randlimb () % 4;
+ mpfr_set_prec (y, yprec);
+ compare = TEST_FUNCTION (y, x, rnd);
+ if (mpfr_can_round (y, yprec, rnd, rnd, prec))
+ {
+ mpfr_set (t, y, rnd);
+ inexact = TEST_FUNCTION (z, x, rnd);
+ if (mpfr_cmp (t, z))
+ {
+ printf ("results differ for x=");
+ mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
+ printf (" prec=%u rnd_mode=%s\n", (unsigned) prec,
+ mpfr_print_rnd_mode (rnd));
+ printf ("got ");
+ mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
+ puts ("");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
+ puts ("");
+ printf ("approx ");
+ mpfr_print_binary (y);
+ puts ("");
+ exit (1);
+ }
+ compare2 = mpfr_cmp (t, y);
+ /* if rounding to nearest, cannot know the sign of t - f(x)
+ because of composed rounding: y = o(f(x)) and t = o(y) */
+ if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
+ compare = compare + compare2;
+ else
+ compare = inexact; /* cannot determine sign(t-f(x)) */
+ if (((inexact == 0) && (compare != 0)) ||
+ ((inexact > 0) && (compare <= 0)) ||
+ ((inexact < 0) && (compare >= 0)))
+ {
+ printf ("Wrong inexact flag for rnd=%s: expected %d, got %d"
+ "\n", mpfr_print_rnd_mode (rnd), compare, inexact);
+ printf ("x="); mpfr_print_binary (x); puts ("");
+ printf ("y="); mpfr_print_binary (y); puts ("");
+ printf ("t="); mpfr_print_binary (t); puts ("");
+ exit (1);
+ }
+ }
+ }
}
mpfr_clear (x);
diff --git a/tests/tget_d.c b/tests/tget_d.c
index 5d40ac12f..637038f3e 100644
--- a/tests/tget_d.c
+++ b/tests/tget_d.c
@@ -57,10 +57,9 @@ check_denorms ()
dd = mpfr_get_d (x, rnd_mode);
if (d2 != dd) /* should be k * 2^(-1022-n) for n < 53 */
{
- fprintf (stderr,
- "Wrong result for %d * 2^(%d), rnd_mode %d\n",
- k, -1022-n, rnd_mode);
- fprintf (stderr, "got %.20e instead of %.20e\n", dd, d2);
+ printf ("Wrong result for %d * 2^(%d), rnd_mode %d\n",
+ k, -1022-n, rnd_mode);
+ printf ("got %.20e instead of %.20e\n", dd, d2);
fail = 1;
}
f *= 0.5;
diff --git a/tests/tget_str.c b/tests/tget_str.c
index 0792229f2..04ff98621 100644
--- a/tests/tget_str.c
+++ b/tests/tget_str.c
@@ -40,8 +40,8 @@ check3 (double d, mp_rnd_t rnd, char *res)
str = mpfr_get_str (NULL, &e, 10, 5, x, rnd);
if (strcmp (str, res))
{
- fprintf (stderr, "Error in mpfr_get_str for x=%1.20e\n", d);
- fprintf (stderr, "got %s instead of %s\n", str, res);
+ printf ("Error in mpfr_get_str for x=%1.20e\n", d);
+ printf ("got %s instead of %s\n", str, res);
exit (1);
}
mpfr_clear (x);
@@ -64,7 +64,8 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 4, 2, x, GMP_RNDU);
if (strcmp (s, "20") || (e != 1))
{
- fprintf(stderr, "Error in mpfr_get_str: 2- rounded up with 2 digits in base 4\n");
+ printf ("Error in mpfr_get_str: 2- rounded up with 2 digits"
+ " in base 4\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -85,14 +86,16 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 3, 21, x, GMP_RNDU);
if (strcmp (s, "102002022201221111211") || (e != 21))
{
- fprintf(stderr, "Error in mpfr_get_str: 2^32-2^(-31) rounded up with 21 digits in base 3\n");
+ printf ("Error in mpfr_get_str: 2^32-2^(-31) rounded up with"
+ " 21 digits in base 3\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
s = mpfr_get_str (NULL, &e, 3, 20, x, GMP_RNDU);
if (strcmp (s, "10200202220122111122") || (e != 21))
{
- fprintf(stderr, "Error in mpfr_get_str: 2^32-2^(-31) rounded up with 20 digits in base 3\n");
+ printf ("Error in mpfr_get_str: 2^32-2^(-31) rounded up with"
+ " 20 digits in base 3\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -105,7 +108,8 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 6, 2, x, GMP_RNDN);
if (strcmp (s, "10") || (e != 2))
{
- fprintf(stderr, "Error in mpfr_get_str: 6.5 rounded to nearest with 2 digits in base 6\n");
+ printf ("Error in mpfr_get_str: 6.5 rounded to nearest with"
+ " 2 digits in base 6\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -114,8 +118,9 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 6, 2, x, GMP_RNDN);
if (strcmp (s, "11") || (e != 2))
{
- fprintf(stderr, "Error in mpfr_get_str: 6.5+ rounded to nearest with 2 digits in base 6\n");
- fprintf(stderr, "got %se%d instead of 11e2\n", s, (int) e);
+ printf ("Error in mpfr_get_str: 6.5+ rounded to nearest with"
+ " 2 digits in base 6\ngot %se%d instead of 11e2\n",
+ s, (int) e);
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -125,7 +130,8 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 6, 2, x, GMP_RNDN);
if (strcmp (s, "10") || (e != 2))
{
- fprintf(stderr, "Error in mpfr_get_str: 6.5- rounded to nearest with 2 digits in base 6\n");
+ printf ("Error in mpfr_get_str: 6.5- rounded to nearest with"
+ " 2 digits in base 6\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -136,9 +142,10 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 2, 2, x, GMP_RNDU);
if (strcmp (s, "10") || (e != 4))
{
- fprintf(stderr, "Error in mpfr_get_str: 7 rounded up with 2 bits should give 0.10e3 instead of 0.%s*2^%d\n", s, (int) e);
- exit (1);
- }
+ printf ("Error in mpfr_get_str: 7 rounded up with 2 bits should"
+ " give 0.10e3 instead of 0.%s*2^%d\n", s, (int) e);
+ exit (1);
+ }
(*__gmp_free_func) (s, strlen (s) + 1);
/* problem found by Fabrice Rouillier */
@@ -153,11 +160,12 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 2, 4, x, GMP_RNDU);
if (strcmp (s, "1011") || (e != 10))
{
- fprintf(stderr, "Error in mpfr_get_str: 688 printed up to 4 bits should give 1.011e9\ninstead of ");
- mpfr_out_str (stderr, 2, 4, x, GMP_RNDU);
- puts ("");
- exit (1);
- }
+ printf ("Error in mpfr_get_str: 688 printed up to 4 bits should"
+ " give 1.011e9\ninstead of ");
+ mpfr_out_str (stdout, 2, 4, x, GMP_RNDU);
+ puts ("");
+ exit (1);
+ }
(*__gmp_free_func) (s, strlen (s) + 1);
mpfr_set_prec (x, 38);
@@ -165,7 +173,7 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 8, 10, x, GMP_RNDU);
if (strcmp (s, "1073721522") || (e != -1))
{
- fprintf (stderr, "Error in mpfr_get_str (3): s=%s e=%d\n", s, (int) e);
+ printf ("Error in mpfr_get_str (3): s=%s e=%d\n", s, (int) e);
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -175,7 +183,7 @@ check_small (void)
s = mpfr_get_str (NULL, &e, 19, 12, x, GMP_RNDU);
if (strcmp (s, "b1cgfa4gha0h") || (e != 107))
{
- fprintf (stderr, "Error in mpfr_get_str (4): s=%s e=%d\n", s, (int) e);
+ printf ("Error in mpfr_get_str (4): s=%s e=%d\n", s, (int) e);
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -298,8 +306,8 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 1000, x, GMP_RNDN);
if (s[999] != '1') /* s must be 5.04383...689071e-309 */
{
- fprintf (stderr, "Error in check_large: expected '689071', got '%s'\n",
- s + 994);
+ printf ("Error in check_large: expected '689071', got '%s'\n",
+ s + 994);
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -308,8 +316,8 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDN);
if (strcmp (s, "12") || (e != 1000))
{
- fprintf (stderr, "Error in check_large: expected 0.12e1000\n");
- fprintf (stderr, "got %se%d\n", s, (int) e);
+ printf ("Error in check_large: expected 0.12e1000\n");
+ printf ("got %se%d\n", s, (int) e);
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -318,7 +326,7 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 1000, x, GMP_RNDN);
if (strcmp (s, "@NaN@"))
{
- fprintf (stderr, "Error for NaN\n");
+ printf ("Error for NaN\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -329,7 +337,7 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 1000, x, GMP_RNDN);
if (strcmp (s, "@Inf@"))
{
- fprintf (stderr, "Error for Inf\n");
+ printf ("Error for Inf\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -340,7 +348,7 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 1000, x, GMP_RNDN);
if (strcmp (s, "-@Inf@"))
{
- fprintf (stderr, "Error for -Inf\n");
+ printf ("Error for -Inf\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -351,7 +359,7 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDN);
if (e != 0 || strcmp (s, "00"))
{
- fprintf (stderr, "Error for 0.0\n");
+ printf ("Error for 0.0\n");
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -361,8 +369,7 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDN);
if (e != 0 || strcmp (s, "-00"))
{
- fprintf (stderr, "Error for -0.0\n");
- fprintf (stderr, "got %se%d\n", s, (int) e);
+ printf ("Error for -0.0\ngot %se%d\n", s, (int) e);
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
@@ -399,7 +406,7 @@ check_special (int b, mp_prec_t p)
/* s should be 1 followed by (m-1) zeros, and e should be i+1 */
if ((e != i+1) || strncmp (s, s2, m) != 0)
{
- fprintf (stderr, "Error in mpfr_get_str for %u^%u\n", b, i);
+ printf ("Error in mpfr_get_str for %u^%u\n", b, i);
exit (1);
}
}
@@ -415,8 +422,8 @@ check_special (int b, mp_prec_t p)
for (j=0; (j < i) && (s[j] == c); j++);
if ((j < i) || (e != i))
{
- fprintf (stderr, "Error in mpfr_get_str for %u^%u-1\n", b, i);
- fprintf (stderr, "got 0.%s*2^%d\n", s, (int) e);
+ printf ("Error in mpfr_get_str for %u^%u-1\n", b, i);
+ printf ("got 0.%s*2^%d\n", s, (int) e);
exit (1);
}
}
@@ -426,8 +433,8 @@ check_special (int b, mp_prec_t p)
/* should be b^i */
if ((e != i+1) || strncmp (s, s2, i - 1) != 0)
{
- fprintf (stderr, "Error in mpfr_get_str for %u^%u-1\n", b, i);
- fprintf (stderr, "got 0.%s*2^%d\n", s, (int) e);
+ printf ("Error in mpfr_get_str for %u^%u-1\n", b, i);
+ printf ("got 0.%s*2^%d\n", s, (int) e);
exit (1);
}
}
diff --git a/tests/thypot.c b/tests/thypot.c
index 648548f3f..4a9440a14 100644
--- a/tests/thypot.c
+++ b/tests/thypot.c
@@ -28,7 +28,7 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpfr-impl.h"
#include "mpfr-test.h"
-
+
#define TEST_FUNCTION mpfr_hypot
static void
@@ -52,11 +52,11 @@ test_large (void)
mpfr_hypot (t, x, y, GMP_RNDN);
if (mpfr_cmp (z, t))
{
- fprintf (stderr, "Error in test_large: got\n");
- mpfr_out_str (stderr, 2, 0, t, GMP_RNDN);
- fprintf (stderr, "\ninstead of\n");
- mpfr_out_str (stderr, 2, 0, z, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("Error in test_large: got\n");
+ mpfr_out_str (stdout, 2, 0, t, GMP_RNDN);
+ printf ("\ninstead of\n");
+ mpfr_out_str (stdout, 2, 0, z, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -105,61 +105,61 @@ main (int argc, char *argv[])
yprec = prec + 10;
for (n=0; n<N; n++)
- {
- mpfr_random(x1);
- mpfr_random(x2);
+ {
+ mpfr_random(x1);
+ mpfr_random(x2);
if (randlimb () % 2)
- mpfr_neg (x1, x1, GMP_RNDN);
+ mpfr_neg (x1, x1, GMP_RNDN);
if (randlimb () % 2)
- mpfr_neg (x2, x2, GMP_RNDN);
- rnd = randlimb () % 4;
- mpfr_set_prec (y, yprec);
-
- compare =TEST_FUNCTION (y, x1,x2, rnd);
- err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
- if (mpfr_can_round (y, err, rnd, rnd, prec))
- {
- mpfr_set (t, y, rnd);
- inexact = TEST_FUNCTION (z, x1,x2, rnd);
- if (mpfr_cmp (t, z))
- {
- printf ("results differ for x1=");
- mpfr_out_str (stdout, 2, prec, x1, GMP_RNDN);
- printf ("\n et x2=");
- mpfr_out_str (stdout, 2, prec, x2, GMP_RNDN);
- printf (" \n prec=%u rnd_mode=%s\n", prec,
- mpfr_print_rnd_mode (rnd));
- printf (" got ");
+ mpfr_neg (x2, x2, GMP_RNDN);
+ rnd = randlimb () % 4;
+ mpfr_set_prec (y, yprec);
+
+ compare =TEST_FUNCTION (y, x1,x2, rnd);
+ err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
+ if (mpfr_can_round (y, err, rnd, rnd, prec))
+ {
+ mpfr_set (t, y, rnd);
+ inexact = TEST_FUNCTION (z, x1,x2, rnd);
+ if (mpfr_cmp (t, z))
+ {
+ printf ("results differ for x1=");
+ mpfr_out_str (stdout, 2, prec, x1, GMP_RNDN);
+ printf ("\n et x2=");
+ mpfr_out_str (stdout, 2, prec, x2, GMP_RNDN);
+ printf (" \n prec=%u rnd_mode=%s\n", prec,
+ mpfr_print_rnd_mode (rnd));
+ printf (" got ");
mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
- puts ("");
- printf (" expected ");
- mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
- puts ("");
- printf (" approximation was ");
- mpfr_print_binary (y);
- puts ("");
- exit (1);
- }
- compare2 = mpfr_cmp (t, y);
- /* if rounding to nearest, cannot know the sign of t - f(x)
- because of composed rounding: y = o(f(x)) and t = o(y) */
- if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
- compare = compare + compare2;
- else
- compare = inexact; /* cannot determine sign(t-f(x)) */
- if (((inexact == 0) && (compare != 0)) ||
- ((inexact > 0) && (compare <= 0)) ||
- ((inexact < 0) && (compare >= 0)))
- {
- fprintf (stderr, "Wrong inexact flag for rnd=%s: expected %d, got %d\n",
- mpfr_print_rnd_mode (rnd), compare, inexact);
- printf ("x1="); mpfr_print_binary (x1); puts ("");
- printf ("x2="); mpfr_print_binary (x2); puts ("");
- printf ("t="); mpfr_print_binary (t); puts ("");
- exit (1);
- }
- }
- }
+ puts ("");
+ printf (" expected ");
+ mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
+ puts ("");
+ printf (" approximation was ");
+ mpfr_print_binary (y);
+ puts ("");
+ exit (1);
+ }
+ compare2 = mpfr_cmp (t, y);
+ /* if rounding to nearest, cannot know the sign of t - f(x)
+ because of composed rounding: y = o(f(x)) and t = o(y) */
+ if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
+ compare = compare + compare2;
+ else
+ compare = inexact; /* cannot determine sign(t-f(x)) */
+ if (((inexact == 0) && (compare != 0)) ||
+ ((inexact > 0) && (compare <= 0)) ||
+ ((inexact < 0) && (compare >= 0)))
+ {
+ printf ("Wrong inexact flag for rnd=%s: expected %d, got %d"
+ "\n", mpfr_print_rnd_mode (rnd), compare, inexact);
+ printf ("x1="); mpfr_print_binary (x1); puts ("");
+ printf ("x2="); mpfr_print_binary (x2); puts ("");
+ printf ("t="); mpfr_print_binary (t); puts ("");
+ exit (1);
+ }
+ }
+ }
}
mpfr_clear (x1);
diff --git a/tests/tisnan.c b/tests/tisnan.c
index bed502153..31e40e7bd 100644
--- a/tests/tisnan.c
+++ b/tests/tisnan.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_nan_p, mpfr_inf_p and mpfr_number_p.
-Copyright 2001 Free Software Foundation.
+Copyright 2001, 2002, 2003 Free Software Foundation.
This file is part of the MPFR Library.
@@ -37,63 +37,75 @@ main (void)
/* check +infinity gives non-zero for mpfr_inf_p only */
mpfr_set_ui (x, 1L, GMP_RNDZ);
mpfr_div_ui (x, x, 0L, GMP_RNDZ);
- if (mpfr_nan_p (x)) {
- fprintf (stderr, "Error: mpfr_nan_p(+Inf) gives non-zero\n");
- exit (1);
- }
- if (mpfr_inf_p (x) == 0) {
- fprintf (stderr, "Error: mpfr_inf_p(+Inf) gives zero\n");
- exit (1);
- }
- if (mpfr_number_p (x)) {
- fprintf (stderr, "Error: mpfr_number_p(+Inf) gives non-zero\n");
- exit (1);
- }
+ if (mpfr_nan_p (x))
+ {
+ printf ("Error: mpfr_nan_p(+Inf) gives non-zero\n");
+ exit (1);
+ }
+ if (mpfr_inf_p (x) == 0)
+ {
+ printf ("Error: mpfr_inf_p(+Inf) gives zero\n");
+ exit (1);
+ }
+ if (mpfr_number_p (x))
+ {
+ printf ("Error: mpfr_number_p(+Inf) gives non-zero\n");
+ exit (1);
+ }
/* same for -Inf */
mpfr_neg (x, x, GMP_RNDN);
- if (mpfr_nan_p (x)) {
- fprintf (stderr, "Error: mpfr_nan_p(-Inf) gives non-zero\n");
- exit (1);
- }
- if (mpfr_inf_p (x) == 0) {
- fprintf (stderr, "Error: mpfr_inf_p(-Inf) gives zero\n");
- exit (1);
- }
- if (mpfr_number_p (x)) {
- fprintf (stderr, "Error: mpfr_number_p(-Inf) gives non-zero\n");
- exit (1);
- }
+ if (mpfr_nan_p (x))
+ {
+ printf ("Error: mpfr_nan_p(-Inf) gives non-zero\n");
+ exit (1);
+ }
+ if (mpfr_inf_p (x) == 0)
+ {
+ printf ("Error: mpfr_inf_p(-Inf) gives zero\n");
+ exit (1);
+ }
+ if (mpfr_number_p (x))
+ {
+ printf ("Error: mpfr_number_p(-Inf) gives non-zero\n");
+ exit (1);
+ }
/* same for NaN */
mpfr_sub (x, x, x, GMP_RNDN);
- if (mpfr_nan_p (x) == 0) {
- fprintf (stderr, "Error: mpfr_nan_p(NaN) gives zero\n");
- exit (1);
- }
- if (mpfr_inf_p (x)) {
- fprintf (stderr, "Error: mpfr_inf_p(NaN) gives non-zero\n");
- exit (1);
- }
- if (mpfr_number_p (x)) {
- fprintf (stderr, "Error: mpfr_number_p(NaN) gives non-zero\n");
- exit (1);
- }
+ if (mpfr_nan_p (x) == 0)
+ {
+ printf ("Error: mpfr_nan_p(NaN) gives zero\n");
+ exit (1);
+ }
+ if (mpfr_inf_p (x))
+ {
+ printf ("Error: mpfr_inf_p(NaN) gives non-zero\n");
+ exit (1);
+ }
+ if (mpfr_number_p (x))
+ {
+ printf ("Error: mpfr_number_p(NaN) gives non-zero\n");
+ exit (1);
+ }
/* same for an ordinary number */
mpfr_set_ui (x, 1, GMP_RNDN);
- if (mpfr_nan_p (x)) {
- fprintf (stderr, "Error: mpfr_nan_p(1) gives non-zero\n");
- exit (1);
- }
- if (mpfr_inf_p (x)) {
- fprintf (stderr, "Error: mpfr_inf_p(1) gives non-zero\n");
- exit (1);
- }
- if (mpfr_number_p (x) == 0) {
- fprintf (stderr, "Error: mpfr_number_p(1) gives zero\n");
- exit (1);
- }
+ if (mpfr_nan_p (x))
+ {
+ printf ("Error: mpfr_nan_p(1) gives non-zero\n");
+ exit (1);
+ }
+ if (mpfr_inf_p (x))
+ {
+ printf ("Error: mpfr_inf_p(1) gives non-zero\n");
+ exit (1);
+ }
+ if (mpfr_number_p (x) == 0)
+ {
+ printf ("Error: mpfr_number_p(1) gives zero\n");
+ exit (1);
+ }
mpfr_clear (x);
diff --git a/tests/tlog.c b/tests/tlog.c
index b199db5fe..c8e183c2c 100644
--- a/tests/tlog.c
+++ b/tests/tlog.c
@@ -20,7 +20,7 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h>
#include <time.h>
#include "gmp.h"
#include "mpfr.h"
@@ -68,7 +68,7 @@ check1 (double a, mp_rnd_t rnd_mode, double res1, int ck, int max_ulp)
mpfr_log (tres, ta, rnd_mode);
res2 = mpfr_get_d1 (tres);
mpfr_clear (ta);
- mpfr_clear (tres);
+ mpfr_clear (tres);
if (res1 != res2 && !(Isnan(res1) && Isnan(res2)))
{
@@ -89,7 +89,7 @@ static void
check3 (double d, unsigned long prec, mp_rnd_t rnd)
{
mpfr_t x, y;
-
+
mpfr_init2 (x, prec);
mpfr_init2 (y, prec);
mpfr_set_d (x, d, rnd);
@@ -122,7 +122,7 @@ check4 (int N)
sum += cur;
}
d = (double)sum / (double)N;
- fprintf(stderr, "max error : %i \t mean error : %f (in ulps)\n",max,d);
+ printf ("max error : %i \t mean error : %f (in ulps)\n", max, d);
}
static void
@@ -136,27 +136,27 @@ slave (int N, int p)
mpfr_init2(tres, p);
for(i=0;i<N;i++)
{
- d = drand_log();
+ d = drand_log();
mpfr_set_d (ta, d, GMP_RNDN);
mpfr_log (tres, ta, randlimb () % 4 );
}
- mpfr_clear(ta); mpfr_clear(tres);
+ mpfr_clear(ta); mpfr_clear(tres);
printf("fin\n");
}
#endif
-/* examples from Jean-Michel Muller and Vincent Lefevre
+/* examples from Jean-Michel Muller and Vincent Lefevre
Cf http://www.ens-lyon.fr/~jmmuller/Intro-to-TMD.htm
*/
static void
check_worst_cases (void)
{
- check2(1.00089971802309629645, GMP_RNDD, 8.99313519443722736088e-04);
+ check2(1.00089971802309629645, GMP_RNDD, 8.99313519443722736088e-04);
check2(1.00089971802309629645, GMP_RNDN, 8.99313519443722844508e-04);
- check2(1.00089971802309629645, GMP_RNDU, 8.99313519443722844508e-04);
+ check2(1.00089971802309629645, GMP_RNDU, 8.99313519443722844508e-04);
- check2(1.01979300812244555452, GMP_RNDD, 1.95996734891603630047e-02);
+ check2(1.01979300812244555452, GMP_RNDD, 1.95996734891603630047e-02);
check2(1.01979300812244555452, GMP_RNDN, 1.95996734891603664741e-02);
check2(1.01979300812244555452, GMP_RNDU, 1.95996734891603664741e-02);
@@ -217,7 +217,7 @@ check_worst_cases (void)
check2(12.4646345033981766903, GMP_RNDU, 2.52289539471636059531);
check2(17.0953275851761752335, GMP_RNDD, 2.83880518553861849185);
- check2(17.0953275851761752335, GMP_RNDN, 2.83880518553861893594);
+ check2(17.0953275851761752335, GMP_RNDN, 2.83880518553861893594);
check2(17.0953275851761752335, GMP_RNDU, 2.83880518553861893594);
check2(19.8509496207496916043, GMP_RNDD, 2.98825184582516722998);
@@ -230,7 +230,7 @@ check_worst_cases (void)
check2(428.315247165198229595, GMP_RNDD, 6.05985948325268264369);
check2(428.315247165198229595, GMP_RNDN, 6.05985948325268353187);
- check2(428.315247165198229595, GMP_RNDU, 6.05985948325268353187);
+ check2(428.315247165198229595, GMP_RNDU, 6.05985948325268353187);
}
static void
@@ -244,7 +244,7 @@ special (void)
mpfr_log (y, x, GMP_RNDD);
if (mpfr_get_d1 (y) != 1.09861228866810956)
{
- fprintf (stderr, "Error in mpfr_log(3) for GMP_RNDD\n");
+ printf ("Error in mpfr_log(3) for GMP_RNDD\n");
exit (1);
}
@@ -298,14 +298,14 @@ main (int argc, char *argv[])
check2(1.01979300812244555452, GMP_RNDN, 1.95996734891603664741e-02);
check2(10.0,GMP_RNDU,2.30258509299404590110e+00);
- check2(6.0,GMP_RNDU,1.79175946922805517936);
- check2(1.0,GMP_RNDZ,0.0);
+ check2(6.0,GMP_RNDU,1.79175946922805517936);
+ check2(1.0,GMP_RNDZ,0.0);
check2(62.0,GMP_RNDU,4.12713438504509166905);
- check2(0.5,GMP_RNDZ,-6.93147180559945286226e-01);
- check2(3.0,GMP_RNDZ,1.09861228866810956006e+00);
+ check2(0.5,GMP_RNDZ,-6.93147180559945286226e-01);
+ check2(3.0,GMP_RNDZ,1.09861228866810956006e+00);
check2(234375765.0,GMP_RNDU,1.92724362186836231104e+01);
- check2(8.0,GMP_RNDZ,2.07944154167983574765e+00);
- check2(44.0,GMP_RNDU,3.78418963391826146392e+00);
+ check2(8.0,GMP_RNDZ,2.07944154167983574765e+00);
+ check2(44.0,GMP_RNDU,3.78418963391826146392e+00);
check2(1.01979300812244555452, GMP_RNDN, 1.95996734891603664741e-02);
/* bugs found by Vincent Lefe`vre */
d = -4723773766428415.0 / 1180591620717411303424.0;
@@ -331,7 +331,7 @@ main (int argc, char *argv[])
check2(7.3890560989306504,GMP_RNDU,2.0000000000000004); /* exp(2.0) */
check2(7.3890560989306495,GMP_RNDU,2.0); /* exp(2.0) */
check2(7.53428236571286402512e+34,GMP_RNDZ,8.03073567492226345621e+01);
- check2(6.18784121531737948160e+19,GMP_RNDZ,4.55717030391710693493e+01);
+ check2(6.18784121531737948160e+19,GMP_RNDZ,4.55717030391710693493e+01);
check2(1.02560267603047283735e+00,GMP_RNDD,2.52804164149448735987e-02);
check2(7.53428236571286402512e+34,GMP_RNDZ,8.03073567492226345621e+01);
d = 497773706319601.0 / 4398046511104.0;
diff --git a/tests/tlog10.c b/tests/tlog10.c
index b587b68c3..241bf171e 100644
--- a/tests/tlog10.c
+++ b/tests/tlog10.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_log10.
-Copyright 2001, 2002 Free Software Foundation.
+Copyright 2001, 2002, 2003 Free Software Foundation.
Adapted from tsinh.c.
This file is part of the MPFR Library.
@@ -50,7 +50,7 @@ main (int argc, char *argv[])
mpfr_log10 (y, x, GMP_RNDN);
if (mpfr_get_d1 (y) != (double) n)
{
- fprintf (stderr, "log10(10^n) <> n for n=%u\n", n);
+ printf ("log10(10^n) <> n for n=%u\n", n);
exit (1);
}
}
diff --git a/tests/tmul.c b/tests/tmul.c
index 6841552ee..aa28c6eac 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -47,12 +47,14 @@ _check (double x, double y, double res, mp_rnd_t rnd_mode, unsigned int px,
mpfr_set_d(yy, y, rnd_mode);
mpfr_mul(zz, xx, yy, rnd_mode);
z2 = mpfr_get_d1 (zz);
- if (res != z2) {
- printf("mpfr_mul failed for x=%1.20e y=%1.20e with rnd_mode=%s\n", x, y,
- mpfr_print_rnd_mode(rnd_mode));
- printf("correct is %1.20e, mpfr_mul gives %1.20e\n", res, z2);
- if (res!=0.0) exit(1);
- }
+ if (res != z2)
+ {
+ printf ("mpfr_mul failed for x=%1.20e y=%1.20e with rnd_mode=%s\n",
+ x, y, mpfr_print_rnd_mode (rnd_mode));
+ printf ("correct is %1.20e, mpfr_mul gives %1.20e\n", res, z2);
+ if (res != 0.0)
+ exit (1);
+ }
mpfr_clear(xx); mpfr_clear(yy); mpfr_clear(zz);
}
@@ -98,9 +100,9 @@ check24 (float x, float y, mp_rnd_t rnd_mode, float z1)
z2 = (float) mpfr_get_d1 (zz);
if (z1 != z2)
{
- fprintf (stderr, "mpfr_mul failed for x=%1.0f y=%1.0f with prec=24 and"
+ printf ("mpfr_mul failed for x=%1.0f y=%1.0f with prec=24 and"
"rnd=%s\n", x, y, mpfr_print_rnd_mode(rnd_mode));
- fprintf (stderr, "correct result is gives %.10e, mpfr_mul gives %.10e\n", z1, z2);
+ printf ("correct result is gives %.10e, mpfr_mul gives %.10e\n", z1, z2);
exit (1);
}
mpfr_clear(xx);
@@ -168,9 +170,11 @@ check_sign (void)
mpfr_set_d(a, -1.0, GMP_RNDN);
mpfr_set_d(b, 2.0, GMP_RNDN);
mpfr_mul(a, b, b, GMP_RNDN);
- if (mpfr_get_d1 (a) != 4.0) {
- fprintf(stderr,"2.0*2.0 gives %1.20e\n", mpfr_get_d1 (a)); exit(1);
- }
+ if (mpfr_get_d1 (a) != 4.0)
+ {
+ printf ("2.0*2.0 gives %1.20e\n", mpfr_get_d1 (a));
+ exit (1);
+ }
mpfr_clear(a); mpfr_clear(b);
}
@@ -195,7 +199,7 @@ check_exact (void)
mpfr_set_str_raw (b, "1.0010001111100111e-1");
if (mpfr_mul (c, a, b, GMP_RNDZ))
{
- fprintf (stderr, "wrong return value (1)\n");
+ printf ("wrong return value (1)\n");
exit (1);
}
@@ -206,37 +210,37 @@ check_exact (void)
mpfr_set_prec (c, 2 * prec - 2);
mpfr_set_prec (d, 2 * prec);
for (i = 0; i < 1000; i++)
- {
- mpfr_random (a);
- mpfr_random (b);
- rnd = randlimb () % 4;
- inexact = mpfr_mul (c, a, b, rnd);
- if (mpfr_mul (d, a, b, rnd)) /* should be always exact */
- {
- fprintf (stderr, "unexpected inexact return value\n");
- exit (1);
- }
- if ((inexact == 0) && mpfr_cmp (c, d))
- {
- fprintf (stderr, "inexact=0 but results differ\n");
- exit (1);
- }
- else if (inexact && (mpfr_cmp (c, d) == 0))
- {
- fprintf (stderr, "inexact!=0 but results agree\n");
- fprintf (stderr, "prec=%u rnd=%s a=", (unsigned int) prec,
- mpfr_print_rnd_mode (rnd));
- mpfr_out_str (stderr, 2, 0, a, rnd);
- fprintf (stderr, "\nb=");
- mpfr_out_str (stderr, 2, 0, b, rnd);
- fprintf (stderr, "\nc=");
- mpfr_out_str (stderr, 2, 0, c, rnd);
- fprintf (stderr, "\nd=");
- mpfr_out_str (stderr, 2, 0, d, rnd);
- fprintf (stderr, "\n");
- exit (1);
- }
- }
+ {
+ mpfr_random (a);
+ mpfr_random (b);
+ rnd = randlimb () % 4;
+ inexact = mpfr_mul (c, a, b, rnd);
+ if (mpfr_mul (d, a, b, rnd)) /* should be always exact */
+ {
+ printf ("unexpected inexact return value\n");
+ exit (1);
+ }
+ if ((inexact == 0) && mpfr_cmp (c, d))
+ {
+ printf ("inexact=0 but results differ\n");
+ exit (1);
+ }
+ else if (inexact && (mpfr_cmp (c, d) == 0))
+ {
+ printf ("inexact!=0 but results agree\n");
+ printf ("prec=%u rnd=%s a=", (unsigned int) prec,
+ mpfr_print_rnd_mode (rnd));
+ mpfr_out_str (stdout, 2, 0, a, rnd);
+ printf ("\nb=");
+ mpfr_out_str (stdout, 2, 0, b, rnd);
+ printf ("\nc=");
+ mpfr_out_str (stdout, 2, 0, c, rnd);
+ printf ("\nd=");
+ mpfr_out_str (stdout, 2, 0, d, rnd);
+ printf ("\n");
+ exit (1);
+ }
+ }
}
mpfr_clear (a);
diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c
index b2a2b071f..751978ae4 100644
--- a/tests/tmul_2exp.c
+++ b/tests/tmul_2exp.c
@@ -34,39 +34,48 @@ MA 02111-1307, USA. */
int
main (int argc, char *argv[])
{
- double x, z; mpfr_t w; unsigned long k;
+ double x, z; mpfr_t w; unsigned long k;
tests_start_mpfr ();
- mpfr_init2(w, 53);
+ mpfr_init2(w, 53);
mpfr_set_inf (w, 1);
- mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
- if (!MPFR_IS_INF(w)) { fprintf(stderr, "Inf != Inf"); exit(-1); }
-
+ mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
+ if (!MPFR_IS_INF(w))
+ {
+ printf ("Inf != Inf");
+ exit (1);
+ }
+
mpfr_set_nan (w);
- mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
- if (!MPFR_IS_NAN(w)) { fprintf(stderr, "NaN != NaN"); exit(-1); }
-
- for (k = 0; k < 100000; k++) {
- x = DBL_RAND ();
- mpfr_set_d (w, x, 0);
- mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
- if (x != (z = mpfr_get_d1 (w)/1024))
- {
- fprintf(stderr, "%f != %f\n", x, z);
- return -1;
- }
-
- mpfr_set_d(w, x, 0);
- mpfr_div_2exp(w, w, 10, GMP_RNDZ);
- if (x != (z = mpfr_get_d1 (w)*1024))
- {
- fprintf(stderr, "%f != %f\n", x, z);
- mpfr_clear(w);
- return -1;
- }
- }
+ mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
+ if (!MPFR_IS_NAN(w))
+ {
+ printf ("NaN != NaN");
+ exit (1);
+ }
+
+ for (k = 0; k < 100000; k++)
+ {
+ x = DBL_RAND ();
+ mpfr_set_d (w, x, 0);
+ mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
+ if (x != (z = mpfr_get_d1 (w)/1024))
+ {
+ printf ("%f != %f\n", x, z);
+ exit (1);
+ }
+
+ mpfr_set_d(w, x, 0);
+ mpfr_div_2exp(w, w, 10, GMP_RNDZ);
+ if (x != (z = mpfr_get_d1 (w)*1024))
+ {
+ printf ("%f != %f\n", x, z);
+ mpfr_clear (w);
+ exit (1);
+ }
+ }
mpfr_clear(w);
diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c
index 30111acce..cafef1614 100644
--- a/tests/tmul_ui.c
+++ b/tests/tmul_ui.c
@@ -43,31 +43,32 @@ check_inexact (mp_prec_t p)
u = randlimb ();
if (mpfr_mul_ui (z, x, u, GMP_RNDN))
{
- fprintf (stderr, "Error: result should be exact\n");
+ printf ("Error: result should be exact\n");
exit (1);
}
for (q=2; q<=p; q++)
for (rnd=0; rnd<4; rnd++)
{
- mpfr_set_prec (y, q);
- inexact = mpfr_mul_ui (y, x, u, rnd);
- cmp = mpfr_cmp (y, z);
- if (((inexact == 0) && (cmp != 0)) ||
- ((inexact < 0) && (cmp >= 0)) ||
- ((inexact > 0) && (cmp <= 0)))
- {
- fprintf (stderr, "Wrong inexact flag for p=%u, q=%u, rnd=%s\n",
- (unsigned) p, (unsigned) q, mpfr_print_rnd_mode (rnd));
- exit (1);
- }
+ mpfr_set_prec (y, q);
+ inexact = mpfr_mul_ui (y, x, u, rnd);
+ cmp = mpfr_cmp (y, z);
+ if (((inexact == 0) && (cmp != 0)) ||
+ ((inexact < 0) && (cmp >= 0)) ||
+ ((inexact > 0) && (cmp <= 0)))
+ {
+ printf ("Wrong inexact flag for p=%u, q=%u, rnd=%s\n",
+ (unsigned int) p, (unsigned int) q,
+ mpfr_print_rnd_mode (rnd));
+ exit (1);
+ }
}
mpfr_set_prec (x, 2);
mpfr_set_ui (x, 1, GMP_RNDN);
if (mpfr_mul_ui (x, x, 5, GMP_RNDZ) == 0)
{
- fprintf (stderr, "mul_ui(1, 5) cannot be exact with prec=2\n");
+ printf ("mul_ui(1, 5) cannot be exact with prec=2\n");
exit (1);
}
@@ -88,7 +89,7 @@ main (int argc, char *argv[])
for (p=2; p<100; p++)
for (i=1; i<50; i++)
check_inexact (p);
-
+
mpfr_init2 (x, 53);
mpfr_init2 (y, 53);
@@ -97,12 +98,12 @@ main (int argc, char *argv[])
mpfr_mul_ui (x, y, 1, GMP_RNDZ);
if (MPFR_MANT(x)[MPFR_PREC(x)/mp_bits_per_limb] >> (mp_bits_per_limb-1) == 0)
{
- fprintf (stderr, "Error in mpfr_mul_ui: result not normalized\n");
+ printf ("Error in mpfr_mul_ui: result not normalized\n");
exit (1);
}
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "Error in mpfr_mul_ui: 1*y != y\n");
+ printf ("Error in mpfr_mul_ui: 1*y != y\n");
printf ("y= "); mpfr_print_binary (y); puts ("");
printf ("1*y="); mpfr_print_binary (x); puts ("");
exit (1);
@@ -112,7 +113,7 @@ main (int argc, char *argv[])
mpfr_mul_ui (x, x, 3, GMP_RNDU);
if (!mpfr_inf_p (x) || (mpfr_sgn (x) <= 0))
{
- fprintf (stderr, "Error in mpfr_mul_ui: +Inf*3 does not give +Inf\n");
+ printf ("Error in mpfr_mul_ui: +Inf*3 does not give +Inf\n");
exit (1);
}
@@ -120,7 +121,7 @@ main (int argc, char *argv[])
mpfr_mul_ui (x, x, 3, GMP_RNDU);
if (!mpfr_inf_p (x) || (mpfr_sgn (x) >= 0))
{
- fprintf (stderr, "Error in mpfr_mul_ui: -Inf*3 does not give -Inf\n");
+ printf ("Error in mpfr_mul_ui: -Inf*3 does not give -Inf\n");
exit (1);
}
@@ -128,7 +129,7 @@ main (int argc, char *argv[])
mpfr_mul_ui (x, x, 3, GMP_RNDU);
if (!mpfr_nan_p(x))
{
- fprintf (stderr, "Error in mpfr_mul_ui: NaN*3 does not give NaN\n");
+ printf ("Error in mpfr_mul_ui: NaN*3 does not give NaN\n");
exit (1);
}
@@ -136,7 +137,7 @@ main (int argc, char *argv[])
mpfr_mul_ui (x, x, 3, GMP_RNDU);
if (mpfr_get_d1 (x) != 1.0)
{
- fprintf (stderr, "Error in mpfr_mul_ui: U(Z(1/3)*3) does not give 1\n");
+ printf ("Error in mpfr_mul_ui: U(Z(1/3)*3) does not give 1\n");
exit (1);
}
@@ -146,7 +147,7 @@ main (int argc, char *argv[])
mpfr_mul_ui(x, y, 4, GMP_RNDZ);
if (mpfr_cmp_ui(x, 0) <= 0)
{
- fprintf(stderr, "Error in mpfr_mul_ui: 4*3.0 does not give a positive result:\n");
+ printf("Error in mpfr_mul_ui: 4*3.0 does not give a positive result:\n");
mpfr_print_binary(x); puts ("");
printf("mpfr_cmp_ui(x, 0) = %d\n", mpfr_cmp_ui(x, 0));
exit(1);
@@ -159,7 +160,7 @@ main (int argc, char *argv[])
mpfr_set_str_raw (y, "0.101100001E19"); /* 361472 */
if (mpfr_cmp (x, y))
{
- fprintf (stderr, "Error in mul_ui for 1335*(0.100001111E9)\n");
+ printf ("Error in mul_ui for 1335*(0.100001111E9)\n");
printf ("got "); mpfr_print_binary (x); puts ("");
exit(1);
}
@@ -192,7 +193,7 @@ main (int argc, char *argv[])
printf ("Error for 6 * 120\n");
exit (1);
}
-
+
mpfr_set_prec (x, 68);
mpfr_set_prec (y, 64);
mpfr_set_d (x, 2143861251406875.0, GMP_RNDN);
@@ -205,24 +206,25 @@ main (int argc, char *argv[])
printf ("got "); mpfr_print_binary (y); puts ("");
exit (1);
}
-
+
for (xprec = 53; xprec <= 128; xprec++)
{
mpfr_set_prec (x, xprec);
mpfr_set_str_raw (x, "0.1100100100001111110011111000000011011100001100110111E2");
for (yprec = 53; yprec <= 128; yprec++)
- {
- mpfr_set_prec (y, yprec);
- mpfr_mul_ui (y, x, 1, GMP_RNDN);
- if (mpfr_get_d1 (x) != mpfr_get_d1 (y))
- {
- fprintf (stderr, "multiplication by 1.0 fails for xprec=%u, yprec=%u\n", xprec, yprec);
- printf ("expected "); mpfr_print_binary (x); puts ("");
- printf ("got "); mpfr_print_binary (y); puts ("");
- exit (1);
- }
- }
+ {
+ mpfr_set_prec (y, yprec);
+ mpfr_mul_ui (y, x, 1, GMP_RNDN);
+ if (mpfr_get_d1 (x) != mpfr_get_d1 (y))
+ {
+ printf ("multiplication by 1.0 fails for xprec=%u, yprec=%u\n",
+ xprec, yprec);
+ printf ("expected "); mpfr_print_binary (x); puts ("");
+ printf ("got "); mpfr_print_binary (y); puts ("");
+ exit (1);
+ }
+ }
}
mpfr_set_prec (x, 128);
@@ -236,7 +238,6 @@ main (int argc, char *argv[])
printf ("Error for 17 * ULONG_HIGHBIT\n");
exit (1);
}
-
mpfr_clear(x); mpfr_clear(y);
diff --git a/tests/tout_str.c b/tests/tout_str.c
index d0cd7354d..f0b3b7b8d 100644
--- a/tests/tout_str.c
+++ b/tests/tout_str.c
@@ -64,8 +64,8 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDD);
if (strcmp (s, "-12"))
{
- fprintf (stderr, "Error in mpfr_get_str for x=-11.5 and rnd=GMP_RNDD\n");
- fprintf (stderr, "got %s instead of -12\n", s);
+ printf ("Error in mpfr_get_str for x=-11.5 and rnd=GMP_RNDD\n"
+ "got %s instead of -12\n", s);
free (s);
mpfr_clear (x);
exit (1);
@@ -75,7 +75,7 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDU);
if (strcmp (s, "-11"))
{
- fprintf (stderr, "Error in mpfr_get_str for x=-11.5 and rnd=GMP_RNDU\n");
+ printf ("Error in mpfr_get_str for x=-11.5 and rnd=GMP_RNDU\n");
free (s);
mpfr_clear (x);
exit (1);
@@ -93,7 +93,8 @@ check_large (void)
s = mpfr_get_str (NULL, &e, 10, 0, x, GMP_RNDD);
if (e != 0)
{
- fprintf (stderr, "Error in mpfr_get_str for x=0.999999..., exponent is %d instead of 0\n", (int) e);
+ printf ("Error in mpfr_get_str for x=0.999999..., exponent is %d"
+ " instead of 0\n", (int) e);
exit (1);
}
(*__gmp_free_func) (s, strlen (s) + 1);
diff --git a/tests/tpow.c b/tests/tpow.c
index a725d3a7d..3512b6ef6 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -40,7 +40,7 @@ check_pow_ui (void)
mpfr_pow_ui (b, b, 10, GMP_RNDN);
if (mpfr_cmp (a, b))
{
- fprintf (stderr, "Error for mpfr_pow_ui (b, b, ...)\n");
+ printf ("Error for mpfr_pow_ui (b, b, ...)\n");
exit (1);
}
@@ -52,7 +52,7 @@ check_pow_ui (void)
mpfr_pow_ui (a, a, 4049053855UL, GMP_RNDN);
if (!mpfr_inf_p (a) || (mpfr_sgn (a) >= 0))
{
- fprintf (stderr, "Error for (-Inf)^4049053855\n");
+ printf ("Error for (-Inf)^4049053855\n");
exit (1);
}
@@ -60,7 +60,7 @@ check_pow_ui (void)
mpfr_pow_ui (a, a, (unsigned long) 30002752, GMP_RNDN);
if (!mpfr_inf_p (a) || (mpfr_sgn (a) <= 0))
{
- fprintf (stderr, "Error for (-Inf)^30002752\n");
+ printf ("Error for (-Inf)^30002752\n");
exit (1);
}
@@ -86,35 +86,36 @@ check_inexact (mp_prec_t p)
for (q=2; q<=p; q++)
for (rnd=0; rnd<4; rnd++)
{
- mpfr_set_prec (y, q);
- mpfr_set_prec (z, q + 10);
- mpfr_set_prec (t, q);
- inexact = mpfr_pow_ui (y, x, u, rnd);
- cmp = mpfr_pow_ui (z, x, u, rnd);
- if (mpfr_can_round (z, q + 10, rnd, rnd, q))
- {
- cmp = mpfr_set (t, z, rnd) || cmp;
- if (mpfr_cmp (y, t))
- {
- fprintf (stderr, "results differ for u=%lu rnd=%s\n", u,
- mpfr_print_rnd_mode(rnd));
- printf ("x="); mpfr_print_binary (x); puts ("");
- printf ("y="); mpfr_print_binary (y); puts ("");
- printf ("t="); mpfr_print_binary (t); puts ("");
- printf ("z="); mpfr_print_binary (z); puts ("");
- exit (1);
- }
- if (((inexact == 0) && (cmp != 0)) ||
- ((inexact != 0) && (cmp == 0)))
- {
- fprintf (stderr, "Wrong inexact flag for p=%u, q=%u, rnd=%s\n",
- (unsigned) p, (unsigned) q, mpfr_print_rnd_mode (rnd));
- printf ("expected %d, got %d\n", cmp, inexact);
- printf ("u=%lu x=", u); mpfr_print_binary (x); puts ("");
+ mpfr_set_prec (y, q);
+ mpfr_set_prec (z, q + 10);
+ mpfr_set_prec (t, q);
+ inexact = mpfr_pow_ui (y, x, u, rnd);
+ cmp = mpfr_pow_ui (z, x, u, rnd);
+ if (mpfr_can_round (z, q + 10, rnd, rnd, q))
+ {
+ cmp = mpfr_set (t, z, rnd) || cmp;
+ if (mpfr_cmp (y, t))
+ {
+ printf ("results differ for u=%lu rnd=%s\n",
+ u, mpfr_print_rnd_mode(rnd));
+ printf ("x="); mpfr_print_binary (x); puts ("");
+ printf ("y="); mpfr_print_binary (y); puts ("");
+ printf ("t="); mpfr_print_binary (t); puts ("");
+ printf ("z="); mpfr_print_binary (z); puts ("");
+ exit (1);
+ }
+ if (((inexact == 0) && (cmp != 0)) ||
+ ((inexact != 0) && (cmp == 0)))
+ {
+ printf ("Wrong inexact flag for p=%u, q=%u, rnd=%s\n",
+ (unsigned int) p, (unsigned int) q,
+ mpfr_print_rnd_mode (rnd));
+ printf ("expected %d, got %d\n", cmp, inexact);
+ printf ("u=%lu x=", u); mpfr_print_binary (x); puts ("");
printf ("y="); mpfr_print_binary (y); puts ("");
- exit (1);
- }
- }
+ exit (1);
+ }
+ }
}
/* check exact power */
@@ -152,7 +153,7 @@ special ()
mpfr_pow (z, x, y, GMP_RNDN);
if (mpfr_cmp (z, t))
{
- fprintf (stderr, "Error in mpfr_pow for prec=64, rnd=GMP_RNDN\n");
+ printf ("Error in mpfr_pow for prec=64, rnd=GMP_RNDN\n");
exit (1);
}
@@ -164,7 +165,7 @@ special ()
mpfr_pow (z, x, y, GMP_RNDZ);
if (mpfr_get_d1 (z) != 0.60071044650456473235)
{
- fprintf (stderr, "Error in mpfr_pow for prec=53, rnd=GMP_RNDZ\n");
+ printf ("Error in mpfr_pow for prec=53, rnd=GMP_RNDZ\n");
exit (1);
}
@@ -178,7 +179,7 @@ special ()
mpfr_set_str (y, "1.01101001111010101110000101111e-1", 2, GMP_RNDN);
if (mpfr_cmp (z, y))
{
- fprintf (stderr, "Error in mpfr_pow for prec=30, rnd=GMP_RNDN\n");
+ printf ("Error in mpfr_pow for prec=30, rnd=GMP_RNDN\n");
exit (1);
}
@@ -190,12 +191,12 @@ special ()
mpfr_set_str (y, "1.01101011010001100000e-1", 2, GMP_RNDN);
if (mpfr_cmp (z, y))
{
- fprintf (stderr, "Error in mpfr_pow for prec=21, rnd=GMP_RNDZ\n");
- fprintf (stderr, "Expected ");
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, "\nGot ");
- mpfr_out_str (stderr, 2, 0, z, GMP_RNDN);
- fprintf (stderr, "\n");
+ printf ("Error in mpfr_pow for prec=21, rnd=GMP_RNDZ\n");
+ printf ("Expected ");
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf ("\nGot ");
+ mpfr_out_str (stdout, 2, 0, z, GMP_RNDN);
+ printf ("\n");
exit (1);
}
@@ -252,9 +253,8 @@ particular_cases (void)
p = -p;
if (p != q[i][j])
{
- fprintf (stderr,
- "Error in mpfr_pow for particular case (%d,%d):\n"
- "got %d instead of %d\n", i, j, p, q[i][j]);
+ printf ("Error in mpfr_pow for particular case (%d,%d):\n"
+ "got %d instead of %d\n", i, j, p, q[i][j]);
error = 1;
}
}
@@ -286,11 +286,11 @@ underflows(void)
mpfr_pow (y, x, y, GMP_RNDN);
if (!MPFR_IS_FP(y) || mpfr_cmp_ui (y, 0))
{
- fprintf (stderr, "Error in mpfr_pow for ");
- mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
- fprintf (stderr, " ^ (%d/2)\nGot ", i);
- mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
- fprintf (stderr, " instead of 0.\n");
+ printf ("Error in mpfr_pow for ");
+ mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
+ printf (" ^ (%d/2)\nGot ", i);
+ mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
+ printf (" instead of 0.\n");
exit (1);
}
}
diff --git a/tests/tpow3.c b/tests/tpow3.c
index ba5100ef3..77aa85d13 100644
--- a/tests/tpow3.c
+++ b/tests/tpow3.c
@@ -64,60 +64,58 @@ main (int argc, char *argv[])
yprec = prec + 10;
for (n=0; n<N; n++)
- {
-
- mpfr_random (x);
-
- mpfr_random (s);
+ {
+ mpfr_random (x);
+ mpfr_random (s);
if (randlimb () % 2)
mpfr_neg (s, s, GMP_RNDN);
- rnd = randlimb () % 4;
- mpfr_set_prec (y, yprec);
- compare = mpfr_pow (y, x, s, rnd);
- err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
- if (mpfr_can_round (y, err, rnd, rnd, prec))
- {
- mpfr_set (t, y, rnd);
- inexact = mpfr_pow (z,x, s, rnd);
- if (mpfr_cmp (t, z))
- {
- printf ("results differ for x=");
- mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
+ rnd = randlimb () % 4;
+ mpfr_set_prec (y, yprec);
+ compare = mpfr_pow (y, x, s, rnd);
+ err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
+ if (mpfr_can_round (y, err, rnd, rnd, prec))
+ {
+ mpfr_set (t, y, rnd);
+ inexact = mpfr_pow (z,x, s, rnd);
+ if (mpfr_cmp (t, z))
+ {
+ printf ("results differ for x=");
+ mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
printf (" values of the exponential=");
- mpfr_out_str (stdout, 2, prec, s, GMP_RNDN);
- printf (" prec=%u rnd_mode=%s\n", (unsigned) prec,
- mpfr_print_rnd_mode (rnd));
- printf ("got ");
- mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
- puts ("");
- printf ("expected ");
- mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
- puts ("");
- printf ("approx ");
- mpfr_print_binary (y);
- puts ("");
- exit (1);
- }
- compare2 = mpfr_cmp (t, y);
- /* if rounding to nearest, cannot know the sign of t - f(x)
- because of composed rounding: y = o(f(x)) and t = o(y) */
- if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
- compare = compare + compare2;
- else
- compare = inexact; /* cannot determine sign(t-f(x)) */
- if (((inexact == 0) && (compare != 0)) ||
- ((inexact > 0) && (compare <= 0)) ||
- ((inexact < 0) && (compare >= 0)))
- {
- fprintf (stderr, "Wrong inexact flag for rnd=%s: expected %d, got %d\n",
- mpfr_print_rnd_mode (rnd), compare, inexact);
- printf ("x="); mpfr_print_binary (x); puts ("");
- printf ("y="); mpfr_print_binary (y); puts ("");
- printf ("t="); mpfr_print_binary (t); puts ("");
- exit (1);
- }
- }
- }
+ mpfr_out_str (stdout, 2, prec, s, GMP_RNDN);
+ printf (" prec=%u rnd_mode=%s\n", (unsigned int) prec,
+ mpfr_print_rnd_mode (rnd));
+ printf ("got ");
+ mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
+ puts ("");
+ printf ("expected ");
+ mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
+ puts ("");
+ printf ("approx ");
+ mpfr_print_binary (y);
+ puts ("");
+ exit (1);
+ }
+ compare2 = mpfr_cmp (t, y);
+ /* if rounding to nearest, cannot know the sign of t - f(x)
+ because of composed rounding: y = o(f(x)) and t = o(y) */
+ if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
+ compare = compare + compare2;
+ else
+ compare = inexact; /* cannot determine sign(t-f(x)) */
+ if (((inexact == 0) && (compare != 0)) ||
+ ((inexact > 0) && (compare <= 0)) ||
+ ((inexact < 0) && (compare >= 0)))
+ {
+ printf ("Wrong inexact flag for rnd=%s: expected %d, got %d"
+ "\n", mpfr_print_rnd_mode (rnd), compare, inexact);
+ printf ("x="); mpfr_print_binary (x); puts ("");
+ printf ("y="); mpfr_print_binary (y); puts ("");
+ printf ("t="); mpfr_print_binary (t); puts ("");
+ exit (1);
+ }
+ }
+ }
}
mpfr_clear (s);
diff --git a/tests/trandom.c b/tests/trandom.c
index 3c512c59e..c61c17af2 100644
--- a/tests/trandom.c
+++ b/tests/trandom.c
@@ -103,14 +103,15 @@ test_random2 (unsigned long nbtests, unsigned long prec, int verbose)
/* check that lower bits are zero */
if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE))
{
- fprintf (stderr, "Error: mpfr_random2() returns invalid numbers:\n");
+ printf ("Error: mpfr_random2() returns invalid numbers:\n");
mpfr_print_binary (x); puts ("");
exit (1);
}
/* check that exponent is in correct range */
if (mpfr_get_exp (x) != 0)
{
- fprintf (stderr, "Error: mpfr_random2 (.., .., 0) does not return a 0 exponent:\n");
+ printf ("Error: mpfr_random2 (.., .., 0) does not return"
+ " a 0 exponent:\n");
mpfr_print_binary (x); puts ("");
exit (1);
}
@@ -174,7 +175,7 @@ test_urandomb (unsigned long nbtests, unsigned long prec, int verbose)
/* check that lower bits are zero */
if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE))
{
- fprintf (stderr, "Error: mpfr_urandomb() returns invalid numbers:\n");
+ printf ("Error: mpfr_urandomb() returns invalid numbers:\n");
mpfr_print_binary (x); puts ("");
exit (1);
}