1/* test file for mpc_pow_si. 2 3Copyright (C) INRIA, 2009, 2010 4 5This file is part of the MPC Library. 6 7The MPC Library is free software; you can redistribute it and/or modify 8it under the terms of the GNU Lesser General Public License as published by 9the Free Software Foundation; either version 2.1 of the License, or (at your 10option) any later version. 11 12The MPC Library is distributed in the hope that it will be useful, but 13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15License for more details. 16 17You should have received a copy of the GNU Lesser General Public License 18along with the MPC Library; see the file COPYING.LIB. If not, write to 19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 20MA 02111-1307, USA. */ 21 22#include <limits.h> /* for CHAR_BIT */ 23#include "mpc-tests.h" 24 25static void 26compare_mpc_pow (mpfr_prec_t pmax, int iter, unsigned long nbits) 27 /* copied from tpow_ui.c and replaced unsigned by signed */ 28{ 29 mpfr_prec_t p; 30 mpc_t x, y, z, t; 31 long n; 32 int i, inex_pow, inex_pow_si; 33 gmp_randstate_t state; 34 mpc_rnd_t rnd; 35 36 gmp_randinit_default (state); 37 mpc_init3 (y, sizeof (unsigned long) * CHAR_BIT, MPFR_PREC_MIN); 38 for (p = MPFR_PREC_MIN; p <= pmax; p++) 39 for (i = 0; i < iter; i++) 40 { 41 mpc_init2 (x, p); 42 mpc_init2 (z, p); 43 mpc_init2 (t, p); 44 mpc_urandom (x, state); 45 n = (signed long) gmp_urandomb_ui (state, nbits); 46 mpc_set_si (y, n, MPC_RNDNN); 47 for (rnd = 0; rnd < 16; rnd ++) 48 { 49 inex_pow = mpc_pow (z, x, y, rnd); 50 inex_pow_si = mpc_pow_si (t, x, n, rnd); 51 if (mpc_cmp (z, t) != 0) 52 { 53 printf ("mpc_pow and mpc_pow_si differ for x="); 54 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN); 55 printf (" n=%li\n", n); 56 printf ("mpc_pow gives "); 57 mpc_out_str (stdout, 10, 0, z, MPC_RNDNN); 58 printf ("\nmpc_pow_si gives "); 59 mpc_out_str (stdout, 10, 0, t, MPC_RNDNN); 60 printf ("\n"); 61 exit (1); 62 } 63 if (inex_pow != inex_pow_si) 64 { 65 printf ("mpc_pow and mpc_pow_si give different flags for x="); 66 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN); 67 printf (" n=%li\n", n); 68 printf ("mpc_pow gives %d\n", inex_pow); 69 printf ("mpc_pow_si gives %d\n", inex_pow_si); 70 exit (1); 71 } 72 } 73 mpc_clear (x); 74 mpc_clear (z); 75 mpc_clear (t); 76 } 77 mpc_clear (y); 78 gmp_randclear (state); 79} 80 81int 82main (void) 83{ 84 test_start (); 85 86 compare_mpc_pow (100, 5, 19); 87 88 test_end (); 89 90 return 0; 91} 92