summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/RRTest.c71
-rw-r--r--tests/tcos.c55
-rw-r--r--tests/texp.c59
-rw-r--r--tests/texpm1.c35
-rw-r--r--tests/tgeneric.c32
-rw-r--r--tests/tlog.c37
-rw-r--r--tests/tlog10.c37
-rw-r--r--tests/tlog1p.c39
-rw-r--r--tests/tpow.c70
-rw-r--r--tests/tsin.c51
10 files changed, 375 insertions, 111 deletions
diff --git a/tests/RRTest.c b/tests/RRTest.c
index 884b5f46d..1e177479a 100644
--- a/tests/RRTest.c
+++ b/tests/RRTest.c
@@ -2,7 +2,7 @@
Usage:
0) compile this file with NTL
1) compile tadd.c with -DCHECK_EXTERNAL
- 2) ./tadd | egrep -v 'Seed|Inf|NaN' > /tmp/add.log
+ 2) ./tadd | egrep -v 'Seed|Inf|NaN' > /tmp/log
(Warning, this produces a large file.)
3) ./RRTest < /tmp/add.log
*/
@@ -52,32 +52,71 @@ ReadRR (RR &a)
}
void
-Output (RR a)
+Output (RR a, long p)
{
- cout << a.mantissa() << "*2^(" << a.exponent() << ")" << endl;
+ cout << a.mantissa() << "*2^(" << a.exponent() << ") [" << p << "]" << endl;
}
-int main()
+// ulp difference between a and b
+long
+ulp (RR a, RR b, long p)
+{
+ ZZ ma, mb;
+ long ea, eb;
+
+ ma = a.x;
+ ea = a.e;
+ while (NumBits (ma) < p)
+ {
+ ma *= 2;
+ ea --;
+ }
+ mb = b.x;
+ eb = b.e;
+ while (NumBits (mb) < p)
+ {
+ mb *= 2;
+ eb --;
+ }
+ if (ea != eb) abort ();
+ return to_long (ma - mb);
+}
+
+// #define TWO_ARGS /* for functions of two arguments like add, sub, pow */
+
+int
+main (void)
{
RR a, b, c, d;
- long line = 0;
- long p;
+ long line = 0, errors = 0;
+ long pa, pb, pc;
while (!feof(stdin))
{
- if (++line % 1000 == 0)
+ if (++line % 10 == 0)
cout << "line " << line << endl;
- ReadRR (b);
- // ReadRR (c);
- p = ReadRR (a);
- SqrRootPrec (d, b, p);
+ pb = ReadRR (b);
+#ifdef TWO_ARGS
+ pc = ReadRR (c);
+#endif
+ pa = ReadRR (a);
+ RR::SetPrecision(pa);
+ cos (d, b
+#ifdef TWO_ARGS
+ , c
+#endif
+ );
if (d != a)
{
- cerr << "error at line " << line << " for b="; Output(b);
- // cerr << " c="; Output(c);
- cerr << "expected "; Output(a);
- cerr << "got "; Output(d);
- cerr << "prec(d)=" << p << endl;
+ cerr << "error at line " << line << endl;
+ cerr << "b="; Output(b, pb);
+#ifdef TWO_ARGS
+ cerr << " c="; Output(c, pc);
+#endif
+ cerr << "expected "; Output(a, pa);
+ cerr << "got "; Output(d, pa);
+ cerr << "difference is " << ulp (a, d, pa) << " ulps" << endl;
+ cerr << ++errors << " errors" << endl;
}
}
}
diff --git a/tests/tcos.c b/tests/tcos.c
index f5074157a..4ef9885bb 100644
--- a/tests/tcos.c
+++ b/tests/tcos.c
@@ -24,6 +24,29 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
+#ifdef CHECK_EXTERNAL
+static int
+test_cos (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ }
+ res = mpfr_cos (a, b, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_cos mpfr_cos
+#endif
+
static void
check53 (const char *xs, const char *cos_xs, mp_rnd_t rnd_mode)
{
@@ -31,7 +54,7 @@ check53 (const char *xs, const char *cos_xs, mp_rnd_t rnd_mode)
mpfr_inits2 (53, xx, c, NULL);
mpfr_set_str1 (xx, xs); /* should be exact */
- mpfr_cos (c, xx, rnd_mode);
+ test_cos (c, xx, rnd_mode);
if (mpfr_cmp_str1 (c, cos_xs))
{
printf ("mpfr_cos failed for x=%s, rnd=%s\n",
@@ -44,7 +67,7 @@ check53 (const char *xs, const char *cos_xs, mp_rnd_t rnd_mode)
mpfr_clears (xx, c, NULL);
}
-#define TEST_FUNCTION mpfr_cos
+#define TEST_FUNCTION test_cos
#include "tgeneric.c"
static void
@@ -56,7 +79,7 @@ check_nans (void)
mpfr_init2 (y, 123L);
mpfr_set_nan (x);
- mpfr_cos (y, x, GMP_RNDN);
+ test_cos (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: cos(NaN) != NaN\n");
@@ -64,7 +87,7 @@ check_nans (void)
}
mpfr_set_inf (x, 1);
- mpfr_cos (y, x, GMP_RNDN);
+ test_cos (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: cos(Inf) != NaN\n");
@@ -72,7 +95,7 @@ check_nans (void)
}
mpfr_set_inf (x, -1);
- mpfr_cos (y, x, GMP_RNDN);
+ test_cos (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: cos(-Inf) != NaN\n");
@@ -81,14 +104,14 @@ check_nans (void)
/* cos(+/-0) = 1 */
mpfr_set_ui (x, 0, GMP_RNDN);
- mpfr_cos (y, x, GMP_RNDN);
+ test_cos (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 1))
{
printf ("Error: cos(+0) != 1\n");
exit (1);
}
mpfr_neg (x, x, GMP_RNDN);
- mpfr_cos (y, x, GMP_RNDN);
+ test_cos (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 1))
{
printf ("Error: cos(-0) != 1\n");
@@ -100,7 +123,7 @@ check_nans (void)
mpfr_set_prec (x, 20000);
mpfr_const_pi (x, GMP_RNDD); mpfr_div_2ui (x, x, 1, GMP_RNDN);
mpfr_set_prec (y, 24);
- mpfr_cos (y, x, GMP_RNDN);
+ test_cos (y, x, GMP_RNDN);
if (mpfr_cmp_str (y, "0.111001010110100011000001E-20000", 2, GMP_RNDN))
{
printf("Error computing cos(~Pi/2)\n");
@@ -124,7 +147,7 @@ special_overflow (void)
set_emin (-125);
set_emax (128);
mpfr_set_str_binary (x, "0.111101010110110011101101E6");
- mpfr_cos (y, x, GMP_RNDZ);
+ test_cos (y, x, GMP_RNDZ);
set_emin (MPFR_EMIN_MIN);
set_emax (MPFR_EMAX_MAX);
@@ -148,12 +171,12 @@ main (int argc, char *argv[])
mpfr_set_prec (x, 53);
mpfr_set_prec (y, 2);
mpfr_set_str (x, "9.81333845856942e-1", 10, GMP_RNDN);
- mpfr_cos (y, x, GMP_RNDN);
+ test_cos (y, x, GMP_RNDN);
mpfr_set_prec (x, 30);
mpfr_set_prec (y, 30);
mpfr_set_str_binary (x, "1.00001010001101110010100010101e-1");
- mpfr_cos (y, x, GMP_RNDU);
+ test_cos (y, x, GMP_RNDU);
mpfr_set_str_binary (x, "1.10111100010101011110101010100e-1");
if (mpfr_cmp (y, x))
{
@@ -166,7 +189,7 @@ main (int argc, char *argv[])
mpfr_set_prec (x, 59);
mpfr_set_prec (y, 59);
mpfr_set_str_binary (x, "1.01101011101111010011111110111111111011011101100111100011e-3");
- mpfr_cos (y, x, GMP_RNDU);
+ test_cos (y, x, GMP_RNDU);
mpfr_set_str_binary (x, "1.1111011111110010001001001011100111101110100010000010010011e-1");
if (mpfr_cmp (y, x))
{
@@ -179,7 +202,7 @@ main (int argc, char *argv[])
mpfr_set_prec (x, 5);
mpfr_set_prec (y, 5);
mpfr_set_str_binary (x, "1.1100e-2");
- mpfr_cos (y, x, GMP_RNDD);
+ test_cos (y, x, GMP_RNDD);
mpfr_set_str_binary (x, "1.1100e-1");
if (mpfr_cmp (y, x))
{
@@ -193,7 +216,7 @@ main (int argc, char *argv[])
mpfr_set_str_binary (x, "0.10001000001001011000100001E-6");
mpfr_set_str_binary (y, "0.1111111111111101101111001100001");
- mpfr_cos (x, x, GMP_RNDN);
+ test_cos (x, x, GMP_RNDN);
if (mpfr_cmp (x, y))
{
printf ("Error for prec=32 (1)\n");
@@ -202,7 +225,7 @@ main (int argc, char *argv[])
mpfr_set_str_binary (x, "-0.1101011110111100111010011001011E-1");
mpfr_set_str_binary (y, "0.11101001100110111011011010100011");
- mpfr_cos (x, x, GMP_RNDN);
+ test_cos (x, x, GMP_RNDN);
if (mpfr_cmp (x, y))
{
printf ("Error for prec=32 (2)\n");
@@ -212,7 +235,7 @@ main (int argc, char *argv[])
/* huge argument reduction */
mpfr_set_str_binary (x, "0.10000010000001101011101111001011E40");
mpfr_set_str_binary (y, "0.10011000001111010000101011001011E-1");
- mpfr_cos (x, x, GMP_RNDN);
+ test_cos (x, x, GMP_RNDN);
if (mpfr_cmp (x, y))
{
printf ("Error for prec=32 (3)\n");
diff --git a/tests/texp.c b/tests/texp.c
index c2759c88b..a7140792d 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -24,6 +24,29 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
+#ifdef CHECK_EXTERNAL
+static int
+test_exp (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ }
+ res = mpfr_exp (a, b, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_exp mpfr_exp
+#endif
+
/* returns the number of ulp of error */
static void
check3 (const char *op, mp_rnd_t rnd, const char *res)
@@ -34,7 +57,7 @@ check3 (const char *op, mp_rnd_t rnd, const char *res)
/* y negative. If we forget to set the sign in mpfr_exp, we'll see it. */
mpfr_set_si (y, -1, GMP_RNDN);
mpfr_set_str1 (x, op);
- mpfr_exp (y, x, rnd);
+ test_exp (y, x, rnd);
if (mpfr_cmp_str1 (y, res) )
{
printf ("mpfr_exp failed for x=%s, rnd=%s\n",
@@ -55,14 +78,14 @@ check_worst_case (const char *Xs, const char *expxs)
mpfr_inits2(53, x, y, NULL);
mpfr_set_str1(x, Xs);
- mpfr_exp(y, x, GMP_RNDD);
+ test_exp(y, x, GMP_RNDD);
if (mpfr_cmp_str1 (y, expxs))
{
printf ("exp(x) rounded towards -infinity is wrong\n");
exit(1);
}
mpfr_set_str1(x, Xs);
- mpfr_exp(x, x, GMP_RNDU);
+ test_exp(x, x, GMP_RNDU);
mpfr_add_one_ulp(y, GMP_RNDN);
if (mpfr_cmp(x,y))
{
@@ -177,7 +200,7 @@ compare_exp2_exp3 (int n)
mpfr_clear (z);
}
-#define TEST_FUNCTION mpfr_exp
+#define TEST_FUNCTION test_exp
#include "tgeneric.c"
static void
@@ -192,7 +215,7 @@ check_special ()
/* check exp(NaN) = NaN */
mpfr_set_nan (x);
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
if (!mpfr_nan_p (y))
{
printf ("Error for exp(NaN)\n");
@@ -201,7 +224,7 @@ check_special ()
/* check exp(+inf) = +inf */
mpfr_set_inf (x, 1);
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
{
printf ("Error for exp(+inf)\n");
@@ -210,7 +233,7 @@ check_special ()
/* check exp(-inf) = +0 */
mpfr_set_inf (x, -1);
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
{
printf ("Error for exp(-inf)\n");
@@ -221,7 +244,7 @@ check_special ()
emax = mpfr_get_emax ();
set_emax (10);
mpfr_set_ui (x, 7, GMP_RNDN);
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
{
printf ("Error for exp(7) for emax=10\n");
@@ -233,7 +256,7 @@ check_special ()
emin = mpfr_get_emin ();
set_emin (-10);
mpfr_set_si (x, -9, GMP_RNDN);
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
{
printf ("Error for exp(-9) for emin=-10\n");
@@ -246,26 +269,26 @@ check_special ()
/* check case EXP(x) < -precy */
mpfr_set_prec (y, 2);
mpfr_set_str_binary (x, "-0.1E-3");
- mpfr_exp (y, x, GMP_RNDD);
+ test_exp (y, x, GMP_RNDD);
if (mpfr_cmp_ui_2exp (y, 3, -2))
{
printf ("Error for exp(-1/16), prec=2, RNDD\n");
exit (1);
}
- mpfr_exp (y, x, GMP_RNDZ);
+ test_exp (y, x, GMP_RNDZ);
if (mpfr_cmp_ui (y, 1))
{
printf ("Error for exp(-1/16), prec=2, RNDZ\n");
exit (1);
}
mpfr_set_str_binary (x, "0.1E-3");
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 1))
{
printf ("Error for exp(1/16), prec=2, RNDN\n");
exit (1);
}
- mpfr_exp (y, x, GMP_RNDU);
+ test_exp (y, x, GMP_RNDU);
if (mpfr_cmp_ui_2exp (y, 3, -1))
{
printf ("Error for exp(1/16), prec=2, RNDU\n");
@@ -276,12 +299,12 @@ check_special ()
mpfr_set_prec (x, 53);
mpfr_set_prec (y, 53);
mpfr_set_str_binary (x, "1.1101011000111101011110000111010010101001101001110111e28");
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
mpfr_set_prec (x, 153);
mpfr_set_prec (z, 153);
mpfr_set_str_binary (x, "1.1101011000111101011110000111010010101001101001110111e28");
- mpfr_exp (z, x, GMP_RNDN);
+ test_exp (z, x, GMP_RNDN);
mpfr_prec_round (z, 53, GMP_RNDN);
if (mpfr_cmp (y, z))
@@ -304,7 +327,7 @@ check_special ()
mpfr_set_str_binary (x, "0.11110000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000"
"00000000E4");
- mpfr_exp (y, x, GMP_RNDN);
+ test_exp (y, x, GMP_RNDN);
if (mpfr_cmp_str (y, "0.11000111100001100110010101111101011010010101010000"
"1101110111100010111001011111111000110111001011001101010"
"01E22", 2, GMP_RNDN))
@@ -320,7 +343,7 @@ check_special ()
/* Check for overflow producing a segfault with HUGE exponent */
mpfr_set_ui (x, 3, GMP_RNDN);
mpfr_mul_2ui (x, x, 32, GMP_RNDN);
- mpfr_exp (y, x, GMP_RNDN); /* Can't test return value: May overflow or not*/
+ test_exp (y, x, GMP_RNDN); /* Can't test return value: May overflow or not*/
mpfr_clear (x);
mpfr_clear (y);
@@ -339,7 +362,7 @@ check_inexact (void)
mpfr_set_str_binary (x,
"1.0000000000001001000110100100101000001101101011100101e2");
- inexact = mpfr_exp (y, x, GMP_RNDN);
+ inexact = test_exp (y, x, GMP_RNDN);
if (inexact <= 0)
{
printf ("Wrong inexact flag\n");
diff --git a/tests/texpm1.c b/tests/texpm1.c
index 53ed39e2a..49888144a 100644
--- a/tests/texpm1.c
+++ b/tests/texpm1.c
@@ -25,7 +25,30 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
-#define TEST_FUNCTION mpfr_expm1
+#ifdef CHECK_EXTERNAL
+static int
+test_expm1 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ }
+ res = mpfr_expm1 (a, b, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_expm1 mpfr_expm1
+#endif
+
+#define TEST_FUNCTION test_expm1
#include "tgeneric.c"
static void
@@ -37,7 +60,7 @@ special (void)
mpfr_init (y);
mpfr_set_nan (x);
- mpfr_expm1 (y, x, GMP_RNDN);
+ test_expm1 (y, x, GMP_RNDN);
if (!mpfr_nan_p (y))
{
printf ("Error for expm1(NaN)\n");
@@ -45,7 +68,7 @@ special (void)
}
mpfr_set_inf (x, 1);
- mpfr_expm1 (y, x, GMP_RNDN);
+ test_expm1 (y, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
{
printf ("Error for expm1(+Inf)\n");
@@ -53,7 +76,7 @@ special (void)
}
mpfr_set_inf (x, -1);
- mpfr_expm1 (y, x, GMP_RNDN);
+ test_expm1 (y, x, GMP_RNDN);
if (mpfr_cmp_si (y, -1))
{
printf ("Error for expm1(-Inf)\n");
@@ -61,7 +84,7 @@ special (void)
}
mpfr_set_ui (x, 0, GMP_RNDN);
- mpfr_expm1 (y, x, GMP_RNDN);
+ test_expm1 (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
{
printf ("Error for expm1(+0)\n");
@@ -69,7 +92,7 @@ special (void)
}
mpfr_neg (x, x, GMP_RNDN);
- mpfr_expm1 (y, x, GMP_RNDN);
+ test_expm1 (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) > 0)
{
printf ("Error for expm1(-0)\n");
diff --git a/tests/tgeneric.c b/tests/tgeneric.c
index 17cedd053..9b13a46a3 100644
--- a/tests/tgeneric.c
+++ b/tests/tgeneric.c
@@ -19,11 +19,16 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
+/* define TWO_ARGS for two-argument functions like mpfr_pow */
+
static void
test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N)
{
mp_prec_t prec, yprec;
mpfr_t x, y, z, t;
+#ifdef TWO_ARGS
+ mpfr_t u;
+#endif
mp_rnd_t rnd;
int inexact, compare, compare2;
unsigned int n;
@@ -32,6 +37,9 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N)
mpfr_init (y);
mpfr_init (z);
mpfr_init (t);
+#ifdef TWO_ARGS
+ mpfr_init (u);
+#endif
/* generic test */
for (prec = p0; prec <= p1; prec++)
@@ -45,20 +53,38 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N)
{
#if defined(RAND_FUNCTION)
RAND_FUNCTION (x);
+#ifdef TWO_ARGS
+ RAND_FUNCTION (u);
+#endif
#else
mpfr_random (x);
+#ifdef TWO_ARGS
+ mpfr_random (u);
+#endif
#endif
rnd = (mp_rnd_t) RND_RAND ();
mpfr_set_prec (y, yprec);
+#ifdef TWO_ARGS
+ compare = TEST_FUNCTION (y, x, u, rnd);
+#else
compare = TEST_FUNCTION (y, x, rnd);
+#endif
if (mpfr_can_round (y, yprec, rnd, rnd, prec))
{
mpfr_set (t, y, rnd);
+#ifdef TWO_ARGS
+ inexact = TEST_FUNCTION (z, x, u, rnd);
+#else
inexact = TEST_FUNCTION (z, x, rnd);
+#endif
if (mpfr_cmp (t, z))
{
printf ("results differ for x=");
mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
+#ifdef TWO_ARGS
+ printf ("\nu=");
+ mpfr_out_str (stdout, 2, prec, u, GMP_RNDN);
+#endif
printf (" prec=%u rnd_mode=%s\n", (unsigned) prec,
mpfr_print_rnd_mode (rnd));
printf ("got ");
@@ -86,6 +112,9 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N)
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 ("");
+#ifdef TWO_ARGS
+ printf ("u="); mpfr_print_binary (u); puts ("");
+#endif
printf ("y="); mpfr_print_binary (y); puts ("");
printf ("t="); mpfr_print_binary (t); puts ("");
exit (1);
@@ -98,4 +127,7 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N)
mpfr_clear (y);
mpfr_clear (z);
mpfr_clear (t);
+#ifdef TWO_ARGS
+ mpfr_clear (u);
+#endif
}
diff --git a/tests/tlog.c b/tests/tlog.c
index d6c3efe49..c31d14c59 100644
--- a/tests/tlog.c
+++ b/tests/tlog.c
@@ -24,6 +24,29 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
+#ifdef CHECK_EXTERNAL
+static int
+test_log (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ }
+ res = mpfr_log (a, b, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_log mpfr_log
+#endif
+
static void
check2 (const char *as, mp_rnd_t rnd_mode, const char *res1s)
{
@@ -31,7 +54,7 @@ check2 (const char *as, mp_rnd_t rnd_mode, const char *res1s)
mpfr_inits2 (53, ta, tres, NULL);
mpfr_set_str1 (ta, as);
- mpfr_log (tres, ta, rnd_mode);
+ test_log (tres, ta, rnd_mode);
if (mpfr_cmp_str1 (tres, res1s))
{
@@ -53,7 +76,7 @@ check3 (double d, unsigned long prec, mp_rnd_t rnd)
mpfr_init2 (x, prec);
mpfr_init2 (y, prec);
mpfr_set_d (x, d, rnd);
- mpfr_log (y, x, rnd);
+ test_log (y, x, rnd);
mpfr_out_str (stdout, 10, 0, y, rnd);
puts ("");
mpfr_print_binary (y);
@@ -164,14 +187,14 @@ special (void)
mpfr_set_prec (y, 24*2);
mpfr_set_prec (x, 24);
mpfr_set_str_binary (x, "0.111110101010101011110101E0");
- mpfr_log (y, x, GMP_RNDN);
+ test_log (y, x, GMP_RNDN);
set_emin (MPFR_EMIN_MIN);
set_emax (MPFR_EMAX_MAX);
mpfr_set_prec (y, 53);
mpfr_set_prec (x, 53);
mpfr_set_ui (x, 3, GMP_RNDD);
- mpfr_log (y, x, GMP_RNDD);
+ test_log (y, x, GMP_RNDD);
if (mpfr_cmp_str1 (y, "1.09861228866810956"))
{
printf ("Error in mpfr_log(3) for GMP_RNDD\n");
@@ -183,18 +206,18 @@ special (void)
mpfr_set_prec (y, 3322);
mpfr_set_ui (x, 3, GMP_RNDN);
mpfr_sqrt (x, x, GMP_RNDN);
- mpfr_log (y, x, GMP_RNDN);
+ test_log (y, x, GMP_RNDN);
/* negative argument */
mpfr_set_si (x, -1, GMP_RNDN);
- mpfr_log (y, x, GMP_RNDN);
+ test_log (y, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (y));
mpfr_clear (x);
mpfr_clear (y);
}
-#define TEST_FUNCTION mpfr_log
+#define TEST_FUNCTION test_log
#include "tgeneric.c"
int
diff --git a/tests/tlog10.c b/tests/tlog10.c
index e2aaa5ab0..ea2bb18fe 100644
--- a/tests/tlog10.c
+++ b/tests/tlog10.c
@@ -25,7 +25,30 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
-#define TEST_FUNCTION mpfr_log10
+#ifdef CHECK_EXTERNAL
+static int
+test_log10 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ }
+ res = mpfr_log10 (a, b, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_log10 mpfr_log10
+#endif
+
+#define TEST_FUNCTION test_log10
#include "tgeneric.c"
int
@@ -43,26 +66,26 @@ main (int argc, char *argv[])
/* check NaN */
mpfr_set_nan (x);
- mpfr_log10 (y, x, GMP_RNDN);
+ test_log10 (y, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (y));
/* check Inf */
mpfr_set_inf (x, -1);
- mpfr_log10 (y, x, GMP_RNDN);
+ test_log10 (y, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (y));
mpfr_set_inf (x, 1);
- mpfr_log10 (y, x, GMP_RNDN);
+ test_log10 (y, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0);
/* check negative argument */
mpfr_set_si (x, -1, GMP_RNDN);
- mpfr_log10 (y, x, GMP_RNDN);
+ test_log10 (y, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (y));
/* check log10(1) = 0 */
mpfr_set_ui (x, 1, GMP_RNDN);
- mpfr_log10 (y, x, GMP_RNDN);
+ test_log10 (y, x, GMP_RNDN);
MPFR_ASSERTN((mpfr_cmp_ui (y, 0) == 0) && (MPFR_IS_POS (y)));
/* check log10(10^n)=n */
@@ -70,7 +93,7 @@ main (int argc, char *argv[])
for (n = 1; n <= 15; n++)
{
mpfr_mul_ui (x, x, 10, GMP_RNDN); /* x = 10^n */
- mpfr_log10 (y, x, GMP_RNDN);
+ test_log10 (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, n) )
{
printf ("log10(10^n) <> n for n=%u\n", n);
diff --git a/tests/tlog1p.c b/tests/tlog1p.c
index ffd1df02e..60c6164ce 100644
--- a/tests/tlog1p.c
+++ b/tests/tlog1p.c
@@ -25,7 +25,30 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
-#define TEST_FUNCTION mpfr_log1p
+#ifdef CHECK_EXTERNAL
+static int
+test_log1p (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ }
+ res = mpfr_log1p (a, b, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_log1p mpfr_log1p
+#endif
+
+#define TEST_FUNCTION test_log1p
#include "tgeneric.c"
static void
@@ -36,30 +59,30 @@ special (void)
mpfr_init (x);
mpfr_set_nan (x);
- mpfr_log1p (x, x, GMP_RNDN);
+ test_log1p (x, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (x));
mpfr_set_inf (x, -1);
- mpfr_log1p (x, x, GMP_RNDN);
+ test_log1p (x, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (x));
mpfr_set_inf (x, 1);
- mpfr_log1p (x, x, GMP_RNDN);
+ test_log1p (x, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
mpfr_set_ui (x, 0, GMP_RNDN);
- mpfr_log1p (x, x, GMP_RNDN);
+ test_log1p (x, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS (x));
mpfr_neg (x, x, GMP_RNDN);
- mpfr_log1p (x, x, GMP_RNDN);
+ test_log1p (x, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG (x));
mpfr_set_si (x, -1, GMP_RNDN);
- mpfr_log1p (x, x, GMP_RNDN);
+ test_log1p (x, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
mpfr_set_si (x, -2, GMP_RNDN);
- mpfr_log1p (x, x, GMP_RNDN);
+ test_log1p (x, x, GMP_RNDN);
MPFR_ASSERTN(mpfr_nan_p (x));
mpfr_clear (x);
diff --git a/tests/tpow.c b/tests/tpow.c
index 6d5b92446..39a9ad36c 100644
--- a/tests/tpow.c
+++ b/tests/tpow.c
@@ -26,6 +26,36 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
+#ifdef CHECK_EXTERNAL
+static int
+test_pow (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_number_p (c)
+ && mpfr_get_prec (a) >= 53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ printf (" ");
+ mpfr_print_raw (c);
+ }
+ res = mpfr_pow (a, b, c, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_pow mpfr_pow
+#endif
+
+#define TEST_FUNCTION test_pow
+#define TWO_ARGS
+#include "tgeneric.c"
+
static void
check_pow_ui (void)
{
@@ -176,7 +206,7 @@ check_special_pow_si ()
mpfr_init (b);
mpfr_set_str (a, "2E100000000", 10, GMP_RNDN);
mpfr_set_si (b, -10, GMP_RNDN);
- mpfr_pow (b, a, b, GMP_RNDN);
+ test_pow (b, a, b, GMP_RNDN);
if (!MPFR_IS_ZERO(b))
{
printf("Pow(2E10000000, -10) failed\n");
@@ -257,7 +287,7 @@ check_inexact (mp_prec_t p)
mpfr_set_prec (z, p);
mpfr_set_ui (x, 4, GMP_RNDN);
mpfr_set_str (y, "0.5", 10, GMP_RNDN);
- mpfr_pow (z, x, y, GMP_RNDZ);
+ test_pow (z, x, y, GMP_RNDZ);
mpfr_clear (x);
mpfr_clear (y);
@@ -284,7 +314,7 @@ special ()
}
mpfr_set_ui (x, 2, GMP_RNDN);
mpfr_set_si (y, -2, GMP_RNDN);
- mpfr_pow (x, x, y, GMP_RNDN);
+ test_pow (x, x, y, GMP_RNDN);
if (mpfr_cmp_ui_2exp (x, 1, -2))
{
printf ("Error in pow(x,x,y) for x=2, y=-2\n");
@@ -299,7 +329,7 @@ special ()
mpfr_set_str_binary (y, "0.111110010100110000011101100011010111000010000100101");
mpfr_set_str_binary (t, "0.1110110011110110001000110100100001001111010011111000010000011001");
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
if (mpfr_cmp (z, t))
{
printf ("Error in mpfr_pow for prec=64, rnd=GMP_RNDN\n");
@@ -311,7 +341,7 @@ special ()
mpfr_set_prec (z, 53);
mpfr_set_str (x, "5.68824667828621954868e-01", 10, GMP_RNDN);
mpfr_set_str (y, "9.03327850535952658895e-01", 10, GMP_RNDN);
- mpfr_pow (z, x, y, GMP_RNDZ);
+ test_pow (z, x, y, GMP_RNDZ);
if (mpfr_cmp_d(z, 0.60071044650456473235))
{
printf ("Error in mpfr_pow for prec=53, rnd=GMP_RNDZ\n");
@@ -324,7 +354,7 @@ special ()
mpfr_set_prec (z, 30);
mpfr_set_str (x, "1.00000000001010111110001111011e1", 2, GMP_RNDN);
mpfr_set_str (t, "-0.5", 10, GMP_RNDN);
- mpfr_pow (z, x, t, GMP_RNDN);
+ test_pow (z, x, t, GMP_RNDN);
mpfr_set_str (y, "1.01101001111010101110000101111e-1", 2, GMP_RNDN);
if (mpfr_cmp (z, y))
{
@@ -336,7 +366,7 @@ special ()
mpfr_set_prec (y, 21);
mpfr_set_prec (z, 21);
mpfr_set_str (x, "1.11111100100001100101", 2, GMP_RNDN);
- mpfr_pow (z, x, t, GMP_RNDZ);
+ test_pow (z, x, t, GMP_RNDZ);
mpfr_set_str (y, "1.01101011010001100000e-1", 2, GMP_RNDN);
if (mpfr_cmp (z, y))
{
@@ -352,17 +382,17 @@ special ()
mpfr_set_inf (x, 1);
mpfr_set_prec (y, 2);
mpfr_set_str_binary (y, "1E10");
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
mpfr_set_inf (x, -1);
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
mpfr_set_prec (y, 10);
mpfr_set_str_binary (y, "1.000000001E9");
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_NEG(z));
mpfr_set_str_binary (y, "1.000000001E8");
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
mpfr_set_inf (x, -1);
@@ -370,23 +400,23 @@ special ()
mpfr_set_ui (y, 1, GMP_RNDN);
mpfr_mul_2exp (y, y, mp_bits_per_limb - 1, GMP_RNDN);
/* y = 2^(mp_bits_per_limb - 1) */
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
mpfr_nextabove (y);
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
/* y = 2^(mp_bits_per_limb - 1) + epsilon */
MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
mpfr_nextbelow (y);
mpfr_div_2exp (y, y, 1, GMP_RNDN);
mpfr_nextabove (y);
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
/* y = 2^(mp_bits_per_limb - 2) + epsilon */
MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z));
mpfr_set_si (x, -1, GMP_RNDN);
mpfr_set_prec (y, 2);
mpfr_set_str_binary (y, "1E10");
- mpfr_pow (z, x, y, GMP_RNDN);
+ test_pow (z, x, y, GMP_RNDN);
MPFR_ASSERTN(mpfr_cmp_ui (z, 1) == 0);
mpfr_clear (x);
@@ -440,7 +470,7 @@ particular_cases (void)
if (i == 5 && j == 1)
f();
- mpfr_pow (r, t[i], t[j], GMP_RNDN);
+ test_pow (r, t[i], t[j], GMP_RNDN);
p = mpfr_nan_p (r) ? 0 : mpfr_inf_p (r) ? 1 :
mpfr_cmp_ui (r, 0) == 0 ? 2 :
(int) (fabs (mpfr_get_d (r, GMP_RNDN)) * 128.0);
@@ -483,7 +513,7 @@ underflows (void)
{
mpfr_set_ui (y, i, GMP_RNDN);
mpfr_div_2ui (y, y, 1, GMP_RNDN);
- mpfr_pow (y, x, y, GMP_RNDN);
+ test_pow (y, x, y, GMP_RNDN);
if (!MPFR_IS_FP(y) || mpfr_cmp_ui (y, 0))
{
printf ("Error in mpfr_pow for ");
@@ -509,7 +539,7 @@ overflows (void)
mpfr_init_set_str (a, "5.1e32", 10, GMP_RNDN);
mpfr_init (b);
- mpfr_pow (b, a, a, GMP_RNDN);
+ test_pow (b, a, a, GMP_RNDN);
if (!(mpfr_inf_p (b) && mpfr_sgn (b) > 0))
{
printf ("Error for a^a for a=5.1e32\n");
@@ -540,13 +570,15 @@ main (void)
check_special_pow_si ();
- for (p=2; p<100; p++)
+ for (p = 2; p < 100; p++)
check_inexact (p);
underflows ();
overflows ();
+ test_generic (2, 100, 100);
+
tests_end_mpfr ();
return 0;
}
diff --git a/tests/tsin.c b/tests/tsin.c
index cbe89c35a..d382226ea 100644
--- a/tests/tsin.c
+++ b/tests/tsin.c
@@ -24,6 +24,29 @@ MA 02111-1307, USA. */
#include "mpfr-test.h"
+#ifdef CHECK_EXTERNAL
+static int
+test_sin (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode)
+{
+ int res;
+ int ok = rnd_mode == GMP_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
+ if (ok)
+ {
+ mpfr_print_raw (b);
+ }
+ res = mpfr_sin (a, b, rnd_mode);
+ if (ok)
+ {
+ printf (" ");
+ mpfr_print_raw (a);
+ printf ("\n");
+ }
+ return res;
+}
+#else
+#define test_sin mpfr_sin
+#endif
+
static void
check53 (const char *xs, const char *sin_xs, mp_rnd_t rnd_mode)
{
@@ -32,7 +55,7 @@ check53 (const char *xs, const char *sin_xs, mp_rnd_t rnd_mode)
mpfr_init2 (xx, 53);
mpfr_init2 (s, 53);
mpfr_set_str1 (xx, xs); /* should be exact */
- mpfr_sin (s, xx, rnd_mode);
+ test_sin (s, xx, rnd_mode);
if (mpfr_cmp_str1 (s, sin_xs))
{
printf ("mpfr_sin failed for x=%s, rnd=%s\n",
@@ -63,7 +86,7 @@ test_sign (void)
{
mpfr_set_prec (x, p);
mpfr_mul_ui (x, pid, k, GMP_RNDD);
- mpfr_sin (y, x, GMP_RNDN);
+ test_sin (y, x, GMP_RNDN);
if (MPFR_SIGN(y) > 0)
{
printf ("Error in test_sign for sin(%dpi-epsilon), prec = %d"
@@ -72,7 +95,7 @@ test_sign (void)
exit (1);
}
mpfr_mul_ui (x, piu, k, GMP_RNDU);
- mpfr_sin (y, x, GMP_RNDN);
+ test_sin (y, x, GMP_RNDN);
if (MPFR_SIGN(y) < 0)
{
printf ("Error in test_sign for sin(%dpi+epsilon), prec = %d"
@@ -86,13 +109,13 @@ test_sign (void)
mpfr_set_prec (x, 53);
mpfr_set_prec (y, 53);
mpfr_set_str (x, "6134899525417045", 10, GMP_RNDN);
- mpfr_sin (y, x, GMP_RNDN);
+ test_sin (y, x, GMP_RNDN);
mpfr_set_str_binary (x, "11011010111101011110111100010101010101110000000001011E-106");
MPFR_ASSERTN(mpfr_cmp (x, y) == 0);
/* Bug on Special cases */
mpfr_set_str_binary (x, "0.100011011010111101E-32");
- mpfr_sin (y, x, GMP_RNDN);
+ test_sin (y, x, GMP_RNDN);
if (mpfr_cmp_str (y, "0.10001101101011110100000000000000000000000000000000000E-32", 2, GMP_RNDN))
{
printf("sin special 97 error:\nx=");
@@ -105,7 +128,7 @@ test_sign (void)
mpfr_set_prec (y, 53);
mpfr_set_str_binary (x, "1.1001001000011111101101010100010001000010110100010011");
mpfr_set_str_binary (y, "1.1111111111111111111111111111111111111111111111111111e-1");
- mpfr_sin (x, x, GMP_RNDZ);
+ test_sin (x, x, GMP_RNDZ);
MPFR_ASSERTN(mpfr_cmp (x, y) == 0);
mpfr_clear (pid);
@@ -123,7 +146,7 @@ check_nans (void)
mpfr_init2 (y, 123L);
mpfr_set_nan (x);
- mpfr_sin (y, x, GMP_RNDN);
+ test_sin (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: sin(NaN) != NaN\n");
@@ -131,7 +154,7 @@ check_nans (void)
}
mpfr_set_inf (x, 1);
- mpfr_sin (y, x, GMP_RNDN);
+ test_sin (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: sin(Inf) != NaN\n");
@@ -139,7 +162,7 @@ check_nans (void)
}
mpfr_set_inf (x, -1);
- mpfr_sin (y, x, GMP_RNDN);
+ test_sin (y, x, GMP_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: sin(-Inf) != NaN\n");
@@ -150,7 +173,7 @@ check_nans (void)
mpfr_clear (y);
}
-#define TEST_FUNCTION mpfr_sin
+#define TEST_FUNCTION test_sin
#include "tgeneric.c"
int
@@ -177,7 +200,7 @@ main (int argc, char *argv[])
mpfr_init2 (x, 2);
mpfr_set_str (x, "0.5", 10, GMP_RNDN);
- mpfr_sin (x, x, GMP_RNDD);
+ test_sin (x, x, GMP_RNDD);
if (mpfr_cmp_ui_2exp (x, 3, -3)) /* x != 0.375 = 3/8 */
{
printf ("mpfr_sin(0.5, GMP_RNDD) failed with precision=2\n");
@@ -188,7 +211,7 @@ main (int argc, char *argv[])
mpfr_const_pi (x, GMP_RNDN);
mpfr_mul_ui (x, x, 3L, GMP_RNDN);
mpfr_div_ui (x, x, 2L, GMP_RNDN);
- mpfr_sin (x, x, GMP_RNDN);
+ test_sin (x, x, GMP_RNDN);
if (mpfr_cmp_ui (x, 0) >= 0)
{
printf ("Error: wrong sign for sin(3*Pi/2)\n");
@@ -201,7 +224,7 @@ main (int argc, char *argv[])
mpfr_init2 (c, 4); mpfr_init2 (s, 42);
mpfr_init2 (c2, 4); mpfr_init2 (s2, 42);
- mpfr_sin (s, x, GMP_RNDN);
+ test_sin (s, x, GMP_RNDN);
mpfr_cos (c, x, GMP_RNDN);
mpfr_sin_cos (s2, c2, x, GMP_RNDN);
if (mpfr_cmp (c2, c))
@@ -216,7 +239,7 @@ main (int argc, char *argv[])
}
mpfr_set_str_binary (x, "1.1001001000011111101101010100010001000010110100010011");
- mpfr_sin (x, x, GMP_RNDZ);
+ test_sin (x, x, GMP_RNDZ);
if (mpfr_cmp_str (x, "1.1111111111111111111111111111111111111111111111111111e-1", 2, 0))
{
printf ("Error for x= 1.1001001000011111101101010100010001000010110100010011\nGot ");