1 /* tpow_si -- test file for mpc_pow_si. 2 3 Copyright (C) 2009, 2010, 2011, 2012 INRIA 4 5 This file is part of GNU MPC. 6 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. 11 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 15 more details. 16 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/ . 19 */ 20 21 #include <limits.h> /* for CHAR_BIT */ 22 #include "mpc-tests.h" 23 24 static void 25 compare_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 rnd1, rnd2, 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 (rnd1 = 0; rnd1 < 4; rnd1 ++) 45 for (rnd2 = 0; rnd2 < 4; rnd2 ++) 46 { 47 rnd = MPC_RND (rnd1, rnd2); 48 inex_pow = mpc_pow (z, x, y, rnd); 49 inex_pow_si = mpc_pow_si (t, x, n, rnd); 50 if (mpc_cmp (z, t) != 0) 51 { 52 printf ("mpc_pow and mpc_pow_si differ for x="); 53 mpc_out_str (stdout, 10, 0, x, MPC_RNDNN); 54 printf (" n=%li p=%lu rnd=%d\n", n, p, rnd); 55 printf ("mpc_pow gives "); 56 mpc_out_str (stdout, 10, 0, z, MPC_RNDNN); 57 printf ("\nmpc_pow_si gives "); 58 mpc_out_str (stdout, 10, 0, t, MPC_RNDNN); 59 printf ("\n"); 60 exit (1); 61 } 62 if (inex_pow != inex_pow_si) 63 { 64 printf ("mpc_pow and mpc_pow_si give different flags for x="); 65 mpc_out_str (stdout, 16, 0, x, MPC_RNDNN); 66 printf (" n=%li p=%lu rnd=%d\n", n, p, rnd); 67 printf ("mpc_pow gives %d\n", inex_pow); 68 printf ("mpc_pow_si gives %d\n", inex_pow_si); 69 exit (1); 70 } 71 } 72 mpc_clear (x); 73 mpc_clear (z); 74 mpc_clear (t); 75 } 76 mpc_clear (y); 77 } 78 79 #define MPC_FUNCTION_CALL \ 80 P[0].mpc_inex = mpc_pow_si (P[1].mpc, P[2].mpc, P[3].si, P[4].mpc_rnd) 81 #define MPC_FUNCTION_CALL_REUSE_OP1 \ 82 P[0].mpc_inex = mpc_pow_si (P[1].mpc, P[1].mpc, P[3].si, P[4].mpc_rnd) 83 84 #include "data_check.tpl" 85 86 int 87 main (void) 88 { 89 test_start (); 90 91 data_check_template ("pow_si.dsc", "pow_si.dat"); 92 93 compare_mpc_pow (100, 5, 19); 94 95 test_end (); 96 97 return 0; 98 } 99