1 /* tpow_ui -- test file for mpc_pow_ui.
3 Copyright (C) 2009, 2010 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)
30 int i, inex_pow, inex_pow_ui;
33 mpc_init3 (y, sizeof (unsigned long) * CHAR_BIT, MPFR_PREC_MIN);
34 for (p = MPFR_PREC_MIN; p <= pmax; p++)
35 for (i = 0; i < iter; i++)
40 mpc_urandom (x, rands);
41 n = gmp_urandomb_ui (rands, nbits); /* 0 <= n < 2^nbits */
42 mpc_set_ui (y, n, MPC_RNDNN);
43 for (rnd = 0; rnd < 16; rnd ++)
45 inex_pow = mpc_pow (z, x, y, rnd);
46 inex_pow_ui = mpc_pow_ui (t, x, n, rnd);
47 if (mpc_cmp (z, t) != 0)
49 printf ("mpc_pow and mpc_pow_ui differ for x=");
50 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
51 printf (" n=%lu\n", n);
52 printf ("mpc_pow gives ");
53 mpc_out_str (stdout, 10, 0, z, MPC_RNDNN);
54 printf ("\nmpc_pow_ui gives ");
55 mpc_out_str (stdout, 10, 0, t, MPC_RNDNN);
59 if (inex_pow != inex_pow_ui)
61 printf ("mpc_pow and mpc_pow_ui give different flags for x=");
62 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
63 printf (" n=%lu\n", n);
64 printf ("mpc_pow gives %d\n", inex_pow);
65 printf ("mpc_pow_ui gives %d\n", inex_pow_ui);
77 main (int argc, char *argv[])
81 DECL_FUNC (CCU, f, mpc_pow_ui);
88 if (argc != 3 && argc != 4)
90 printf ("Usage: tpow_ui precision exponent [k]\n");
96 k = (argc > 3) ? atoi (argv[3]) : 1;
100 mpfr_const_pi (mpc_realref (z), GMP_RNDN);
101 mpfr_div_2exp (mpc_realref (z), mpc_realref (z), 2, GMP_RNDN);
102 mpfr_const_log2 (mpc_imagref (z), GMP_RNDN);
104 mpc_pow_ui (res, z, (unsigned long int) n, MPC_RNDNN);
111 data_check (f, "pow_ui.dat");
113 compare_mpc_pow (100, 5, 19);