1 /* tpow_si -- test file for mpc_pow_si.
3 Copyright (C) 2009, 2010, 2011 INRIA
5 This file is part of GNU MPC.
7 GNU MPC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/ .
21 #include <limits.h> /* for CHAR_BIT */
22 #include "mpc-tests.h"
25 compare_mpc_pow (mpfr_prec_t pmax, int iter, unsigned long nbits)
26 /* copied from tpow_ui.c and replaced unsigned by signed */
31 int i, inex_pow, inex_pow_si;
34 mpc_init3 (y, sizeof (unsigned long) * CHAR_BIT, MPFR_PREC_MIN);
35 for (p = MPFR_PREC_MIN; p <= pmax; p++)
36 for (i = 0; i < iter; i++)
41 mpc_urandom (x, rands);
42 n = (signed long) gmp_urandomb_ui (rands, nbits);
43 mpc_set_si (y, n, MPC_RNDNN);
44 for (rnd = 0; rnd < 16; rnd ++)
46 inex_pow = mpc_pow (z, x, y, rnd);
47 inex_pow_si = mpc_pow_si (t, x, n, rnd);
48 if (mpc_cmp (z, t) != 0)
50 printf ("mpc_pow and mpc_pow_si differ for x=");
51 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
52 printf (" n=%li\n", n);
53 printf ("mpc_pow gives ");
54 mpc_out_str (stdout, 10, 0, z, MPC_RNDNN);
55 printf ("\nmpc_pow_si gives ");
56 mpc_out_str (stdout, 10, 0, t, MPC_RNDNN);
60 if (inex_pow != inex_pow_si)
62 printf ("mpc_pow and mpc_pow_si give different flags for x=");
63 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
64 printf (" n=%li\n", n);
65 printf ("mpc_pow gives %d\n", inex_pow);
66 printf ("mpc_pow_si gives %d\n", inex_pow_si);
80 DECL_FUNC (CCS, f, mpc_pow_si);
82 data_check (f, "pow_si.dat");
84 compare_mpc_pow (100, 5, 19);