diff options
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/pow_si.dsc | 31 | ||||
-rw-r--r-- | tests/tpow_si_tmpl.c | 100 |
3 files changed, 134 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 156f803..a519123 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 +TEMPLATED = tadd_tmpl tadd_fr_tmpl tmul_tmpl tpow_si_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 \ @@ -45,7 +45,8 @@ libmpc_tests_la_SOURCES=mpc-tests.h random.c tgeneric.c read_data.c \ print_parameter.c read_description.c read_line.c tpl_mpc.c \ tpl_mpfr.c tpl_native.c -TEMPLATES = data_check.tpl add.dsc add_fr.dsc add_si.dsc add_ui.dsc mul.dsc +TEMPLATES = data_check.tpl add.dsc add_fr.dsc add_si.dsc add_ui.dsc mul.dsc \ + pow_si.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_si.dsc b/tests/pow_si.dsc new file mode 100644 index 0000000..7d9a1f0 --- /dev/null +++ b/tests/pow_si.dsc @@ -0,0 +1,31 @@ +# Description file for mpc_pow_si +# +# 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_si +RETURN: + mpc_inex +OUTPUT: + mpc_ptr +INPUT: + mpc_srcptr + long int + mpc_rnd_t +
\ No newline at end of file diff --git a/tests/tpow_si_tmpl.c b/tests/tpow_si_tmpl.c new file mode 100644 index 0000000..4006e9d --- /dev/null +++ b/tests/tpow_si_tmpl.c @@ -0,0 +1,100 @@ +/* tpow_si_tmpl.c -- test file for mpc_pow_si. + +Copyright (C) 2009, 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 +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 "templates.h" +#include "mpc-tests.h" + +static void +compare_mpc_pow (mpfr_prec_t pmax, int iter, unsigned long nbits) + /* copied from tpow_ui.c and replaced unsigned by signed */ +{ + mpfr_prec_t p; + mpc_t x, y, z, t; + long n; + int i, inex_pow, inex_pow_si; + 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 = (signed long) gmp_urandomb_ui (rands, nbits); + mpc_set_si (y, n, MPC_RNDNN); + for (rnd = 0; rnd < 16; rnd ++) + { + inex_pow = mpc_pow (z, x, y, rnd); + inex_pow_si = mpc_pow_si (t, x, n, rnd); + if (mpc_cmp (z, t) != 0) + { + printf ("mpc_pow and mpc_pow_si differ for x="); + mpc_out_str (stdout, 10, 0, x, MPC_RNDNN); + printf (" n=%li\n", n); + printf ("mpc_pow gives "); + mpc_out_str (stdout, 10, 0, z, MPC_RNDNN); + printf ("\nmpc_pow_si gives "); + mpc_out_str (stdout, 10, 0, t, MPC_RNDNN); + printf ("\n"); + exit (1); + } + if (inex_pow != inex_pow_si) + { + printf ("mpc_pow and mpc_pow_si give different flags for x="); + mpc_out_str (stdout, 10, 0, x, MPC_RNDNN); + printf (" n=%li\n", n); + printf ("mpc_pow gives %d\n", inex_pow); + printf ("mpc_pow_si gives %d\n", inex_pow_si); + exit (1); + } + } + mpc_clear (x); + mpc_clear (z); + mpc_clear (t); + } + mpc_clear (y); +} + +#define MPC_FUNCTION_CALL \ + P[0].mpc_inex = mpc_pow_si (P[1].mpc, P[2].mpc, P[3].si, P[4].mpc_rnd) +#define MPC_FUNCTION_CALL_REUSE_OP1 \ + P[0].mpc_inex = mpc_pow_si (P[1].mpc, P[1].mpc, P[3].si, P[4].mpc_rnd) + +#include "data_check.tpl" + +int +main (void) +{ + DECL_FUNC (CCS, f, mpc_pow_si); + + test_start (); + + data_check_template ("pow_si.dsc", "pow_si.dat"); + + compare_mpc_pow (100, 5, 19); + + test_end (); + + return 0; +} |