1 /* test file for mpc_pow_ui.
3 Copyright (C) 2009, 2010 Paul Zimmermann, Andreas Enge
5 This file is part of the MPC Library.
7 The MPC Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
12 The MPC Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the MPC Library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
22 #include <limits.h> /* for CHAR_BIT */
23 #include "mpc-tests.h"
26 compare_mpc_pow (mp_prec_t pmax, int iter, unsigned long nbits)
31 int i, inex_pow, inex_pow_ui;
32 gmp_randstate_t state;
35 gmp_randinit_default (state);
36 mpc_init3 (y, sizeof (unsigned long) * CHAR_BIT, MPFR_PREC_MIN);
37 for (p = MPFR_PREC_MIN; p <= pmax; p++)
38 for (i = 0; i < iter; i++)
43 mpc_urandom (x, state);
44 n = gmp_urandomb_ui (state, nbits); /* 0 <= n < 2^nbits */
45 mpc_set_ui (y, n, MPC_RNDNN);
46 for (rnd = 0; rnd < 16; rnd ++)
48 inex_pow = mpc_pow (z, x, y, rnd);
49 inex_pow_ui = mpc_pow_ui (t, x, n, rnd);
50 if (mpc_cmp (z, t) != 0)
52 printf ("mpc_pow and mpc_pow_ui differ for x=");
53 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
54 printf (" n=%lu\n", n);
55 printf ("mpc_pow gives ");
56 mpc_out_str (stdout, 10, 0, z, MPC_RNDNN);
57 printf ("\nmpc_pow_ui gives ");
58 mpc_out_str (stdout, 10, 0, t, MPC_RNDNN);
62 if (inex_pow != inex_pow_ui)
64 printf ("mpc_pow and mpc_pow_ui gives different flags for x=");
65 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
66 printf (" n=%lu\n", n);
67 printf ("mpc_pow gives %d\n", inex_pow);
68 printf ("mpc_pow_ui gives %d\n", inex_pow_ui);
77 gmp_randclear (state);
81 main (int argc, char *argv[])
85 DECL_FUNC (CCU, f, mpc_pow_ui);
92 if (argc != 3 && argc != 4)
94 printf ("Usage: tpow_ui precision exponent [k]\n");
99 k = (argc > 3) ? atoi (argv[3]) : 1;
102 mpfr_const_pi (mpc_realref (z), GMP_RNDN);
103 mpfr_div_2exp (mpc_realref (z), mpc_realref (z), 2, GMP_RNDN);
104 mpfr_const_log2 (mpc_imagref (z), GMP_RNDN);
106 mpc_pow_ui (res, z, n, MPC_RNDNN);
113 data_check (f, "pow_ui.dat");
116 mpc_set_ui_ui (z, 3, 2, MPC_RNDNN);
117 mpc_pow_ui (z, z, 3, MPC_RNDNN);
118 if (mpc_cmp_si_si (z, -9, 46) != 0)
120 printf ("Error for mpc_pow_ui (1)\n");
121 printf ("expected (-9,46)\n");
123 mpc_out_str (stdout, 10, 0, z, MPC_RNDNN);
129 compare_mpc_pow (100, 5, 19);