1/* tpow_si -- test file for mpc_pow_si.
2
3Copyright (C) 2009, 2010, 2011 INRIA
4
5This file is part of GNU MPC.
6
7GNU MPC is free software; you can redistribute it and/or modify it under
8the terms of the GNU Lesser General Public License as published by the
9Free Software Foundation; either version 3 of the License, or (at your
10option) any later version.
11
12GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with this program. If not, see http://www.gnu.org/licenses/ .
19*/
20
21#include <limits.h> /* for CHAR_BIT */
22#include "mpc-tests.h"
23
24static void
25compare_mpc_pow (mpfr_prec_t pmax, int iter, unsigned long nbits)
26   /* copied from tpow_ui.c and replaced unsigned by signed */
27{
28  mpfr_prec_t p;
29  mpc_t x, y, z, t;
30  long n;
31  int i, inex_pow, inex_pow_si;
32  mpc_rnd_t rnd;
33
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++)
37      {
38        mpc_init2 (x, p);
39        mpc_init2 (z, p);
40        mpc_init2 (t, p);
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 ++)
45          {
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)
49              {
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);
57                printf ("\n");
58                exit (1);
59              }
60            if (inex_pow != inex_pow_si)
61              {
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);
67                exit (1);
68              }
69          }
70        mpc_clear (x);
71        mpc_clear (z);
72        mpc_clear (t);
73      }
74  mpc_clear (y);
75}
76
77int
78main (void)
79{
80  DECL_FUNC (CCS, f, mpc_pow_si);
81  test_start ();
82  data_check (f, "pow_si.dat");
83
84  compare_mpc_pow (100, 5, 19);
85
86  test_end ();
87
88  return 0;
89}
90