diff options
author | enge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2010-06-17 17:55:29 +0000 |
---|---|---|
committer | enge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2010-06-17 17:55:29 +0000 |
commit | ce4066974514b526d558c76b054d1e4634c20208 (patch) | |
tree | c49cf90c9aff0fa1620bde67b826396ac554920a /tests/tpow_si.c | |
parent | 30efa885cf08e78dcfb648b86a8ea5e07bc3fcb4 (diff) | |
download | mpc-ce4066974514b526d558c76b054d1e4634c20208.tar.gz |
tpow_si.c: copied comparison with pow from tpow_ui.c
pow_ui.dat: added test with exact result that was removed from tpow_ui.c
in previous revision
tpow_ui.c: typo
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@790 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'tests/tpow_si.c')
-rw-r--r-- | tests/tpow_si.c | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/tests/tpow_si.c b/tests/tpow_si.c index 61674e1..55f2b09 100644 --- a/tests/tpow_si.c +++ b/tests/tpow_si.c @@ -19,27 +19,71 @@ along with the MPC 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. */ +#include <limits.h> /* for CHAR_BIT */ #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; + gmp_randstate_t state; + mpc_rnd_t rnd; + + gmp_randinit_default (state); + 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, state); + n = (signed long) gmp_urandomb_ui (state, 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); + gmp_randclear (state); +} + int main (void) { - mpc_t z; - test_start (); - mpc_init2 (z, 5); - mpc_set_ui_ui (z, 3, 2, MPC_RNDNN); - if (mpc_pow_si (z, z, 3, MPC_RNDNN) != MPC_INEX (0, 0)) { - printf ("Error for mpc_pow_si: Result should be exact\n"); - exit (1); - } - if (mpc_cmp_si_si (z, -9, 46) != 0) - { - printf ("Error for mpc_pow_si (1)\n"); - exit (1); - } - mpc_clear (z); + compare_mpc_pow (100, 5, 19); test_end (); |