diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2012-10-29 15:57:12 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2012-10-29 15:57:12 +0000 |
commit | aa0bc442be9598b904f09435af6f141fcac04667 (patch) | |
tree | d724ca850830d8bf552d32cd4d26dca5d5c06e7f | |
parent | 733bfd69eaf7229154fa8458d69a35b10446b7cb (diff) | |
download | mpc-aa0bc442be9598b904f09435af6f141fcac04667.tar.gz |
Add templated tests for pow_ui.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/branches/benchs_tests@1292 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/pow_ui.dsc | 31 | ||||
-rw-r--r-- | tests/tpow_ui_tmpl.c | 126 |
3 files changed, 159 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index a519123..a32c01b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,7 +28,7 @@ AM_LDFLAGS = -no-install LOADLIBES=$(DEFS) -I$(top_srcdir)/src -I$(top_builddir) $(CPPFLAGS) \ $(CFLAGS) -L$(top_builddir)/tests/.libs -lmpc-tests -lmpc -lm $(LIBS) -TEMPLATED = tadd_tmpl tadd_fr_tmpl tmul_tmpl tpow_si_tmpl +TEMPLATED = tadd_tmpl tadd_fr_tmpl tmul_tmpl tpow_si_tmpl tpow_ui_tmpl check_PROGRAMS = tabs tacos tacosh tadd tadd_fr tadd_si tadd_ui targ \ tasin tasinh tatan tatanh tconj tcos tcosh tdiv tdiv_2exp tdiv_fr \ @@ -46,7 +46,7 @@ libmpc_tests_la_SOURCES=mpc-tests.h random.c tgeneric.c read_data.c \ tpl_mpfr.c tpl_native.c TEMPLATES = data_check.tpl add.dsc add_fr.dsc add_si.dsc add_ui.dsc mul.dsc \ - pow_si.dsc + pow_si.dsc pow_ui.dsc EXTRA_DIST = abs.dat acos.dat acosh.dat asin.dat asinh.dat atan.dat \ atanh.dat add.dat add_fr.dat arg.dat conj.dat cos.dat cosh.dat \ diff --git a/tests/pow_ui.dsc b/tests/pow_ui.dsc new file mode 100644 index 0000000..5b2c281 --- /dev/null +++ b/tests/pow_ui.dsc @@ -0,0 +1,31 @@ +# Description file for mpc_pow_ui +# +# Copyright (C) 2008, 2010, 2011, 2012, INRIA +# +# This file is part of GNU MPC. +# +# GNU MPC is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +#o ption) any later version. +# +# GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for +# more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see http://www.gnu.org/licenses/ . +# +# Description file of the function +NAME: + mpc_pow_ui +RETURN: + mpc_inex +OUTPUT: + mpc_ptr +INPUT: + mpc_srcptr + unsigned long int + mpc_rnd_t +
\ No newline at end of file diff --git a/tests/tpow_ui_tmpl.c b/tests/tpow_ui_tmpl.c new file mode 100644 index 0000000..3a630d3 --- /dev/null +++ b/tests/tpow_ui_tmpl.c @@ -0,0 +1,126 @@ +/* tpow_ui_tmpl.c -- test file for mpc_pow_ui. + +Copyright (C) 2009, 2010, 2012 INRIA + +This file is part of GNU MPC. + +GNU MPC is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for +more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see http://www.gnu.org/licenses/ . +*/ + +#include <limits.h> /* for CHAR_BIT */ +#include "mpc-tests.h" + +static void +compare_mpc_pow (mpfr_prec_t pmax, int iter, unsigned long nbits) +{ + mpfr_prec_t p; + mpc_t x, y, z, t; + unsigned long n; + int i, inex_pow, inex_pow_ui; + mpc_rnd_t rnd; + + mpc_init3 (y, sizeof (unsigned long) * CHAR_BIT, MPFR_PREC_MIN); + for (p = MPFR_PREC_MIN; p <= pmax; p++) + for (i = 0; i < iter; i++) + { + mpc_init2 (x, p); + mpc_init2 (z, p); + mpc_init2 (t, p); + mpc_urandom (x, rands); + n = gmp_urandomb_ui (rands, nbits); /* 0 <= n < 2^nbits */ + mpc_set_ui (y, n, MPC_RNDNN); + for (rnd = 0; rnd < 16; rnd ++) + { + inex_pow = mpc_pow (z, x, y, rnd); + inex_pow_ui = mpc_pow_ui (t, x, n, rnd); + if (mpc_cmp (z, t) != 0) + { + printf ("mpc_pow and mpc_pow_ui differ for x="); + mpc_out_str (stdout, 10, 0, x, MPC_RNDNN); + printf (" n=%lu\n", n); + printf ("mpc_pow gives "); + mpc_out_str (stdout, 10, 0, z, MPC_RNDNN); + printf ("\nmpc_pow_ui gives "); + mpc_out_str (stdout, 10, 0, t, MPC_RNDNN); + printf ("\n"); + exit (1); + } + if (inex_pow != inex_pow_ui) + { + printf ("mpc_pow and mpc_pow_ui give different flags for x="); + mpc_out_str (stdout, 10, 0, x, MPC_RNDNN); + printf (" n=%lu\n", n); + printf ("mpc_pow gives %d\n", inex_pow); + printf ("mpc_pow_ui gives %d\n", inex_pow_ui); + exit (1); + } + } + mpc_clear (x); + mpc_clear (z); + mpc_clear (t); + } + mpc_clear (y); +} + +#define MPC_FUNCTION_CALL \ + P[0].mpc_inex = mpc_pow_ui (P[1].mpc, P[2].mpc, P[3].ui, P[4].mpc_rnd) +#define MPC_FUNCTION_CALL_REUSE_OP1 \ + P[0].mpc_inex = mpc_pow_ui (P[1].mpc, P[1].mpc, P[3].ui, P[4].mpc_rnd) + +#include "data_check.tpl" + +int +main (int argc, char *argv[]) +{ + mpc_t z; + + DECL_FUNC (CCU, f, mpc_pow_ui); + + if (argc != 1) + { + mpfr_prec_t p; + long int n, k; + mpc_t res; + if (argc != 3 && argc != 4) + { + printf ("Usage: tpow_ui precision exponent [k]\n"); + exit (1); + } + p = atoi (argv[1]); + n = atoi (argv[2]); + MPC_ASSERT (n >= 0); + k = (argc > 3) ? atoi (argv[3]) : 1; + MPC_ASSERT (k >= 0); + mpc_init2 (z, p); + mpc_init2 (res, p); + mpfr_const_pi (mpc_realref (z), GMP_RNDN); + mpfr_div_2exp (mpc_realref (z), mpc_realref (z), 2, GMP_RNDN); + mpfr_const_log2 (mpc_imagref (z), GMP_RNDN); + while (k--) + mpc_pow_ui (res, z, (unsigned long int) n, MPC_RNDNN); + mpc_clear (z); + mpc_clear (res); + return 0; + } + + test_start (); + + data_check_template ("pow_ui.dsc", "pow_ui.dat"); + + compare_mpc_pow (100, 5, 19); + + test_end (); + + return 0; +} |