buildtools/gcc/mpc/tests/tpow_si.c
Jérôme Duval 3c24538123 Adding inline mpc directory so the MPC library is built as part of GCC 4.5
git-svn-id: file:///srv/svn/repos/haiku/buildtools/trunk@42242 a95241bf-73f2-0310-859d-f6bbb57e9c96
2011-06-19 13:22:38 +00:00

92 lines
2.8 KiB
C

/* test file for mpc_pow_si.
Copyright (C) INRIA, 2009, 2010
This file is part of the MPC Library.
The MPC Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The MPC Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the MPC Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <limits.h> /* for CHAR_BIT */
#include "mpc-tests.h"
static void
compare_mpc_pow (mpfr_prec_t pmax, int iter, unsigned long nbits)
/* copied from tpow_ui.c and replaced unsigned by signed */
{
mpfr_prec_t p;
mpc_t x, y, z, t;
long n;
int i, inex_pow, inex_pow_si;
gmp_randstate_t state;
mpc_rnd_t rnd;
gmp_randinit_default (state);
mpc_init3 (y, sizeof (unsigned long) * CHAR_BIT, MPFR_PREC_MIN);
for (p = MPFR_PREC_MIN; p <= pmax; p++)
for (i = 0; i < iter; i++)
{
mpc_init2 (x, p);
mpc_init2 (z, p);
mpc_init2 (t, p);
mpc_urandom (x, state);
n = (signed long) gmp_urandomb_ui (state, nbits);
mpc_set_si (y, n, MPC_RNDNN);
for (rnd = 0; rnd < 16; rnd ++)
{
inex_pow = mpc_pow (z, x, y, rnd);
inex_pow_si = mpc_pow_si (t, x, n, rnd);
if (mpc_cmp (z, t) != 0)
{
printf ("mpc_pow and mpc_pow_si differ for x=");
mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
printf (" n=%li\n", n);
printf ("mpc_pow gives ");
mpc_out_str (stdout, 10, 0, z, MPC_RNDNN);
printf ("\nmpc_pow_si gives ");
mpc_out_str (stdout, 10, 0, t, MPC_RNDNN);
printf ("\n");
exit (1);
}
if (inex_pow != inex_pow_si)
{
printf ("mpc_pow and mpc_pow_si give different flags for x=");
mpc_out_str (stdout, 10, 0, x, MPC_RNDNN);
printf (" n=%li\n", n);
printf ("mpc_pow gives %d\n", inex_pow);
printf ("mpc_pow_si gives %d\n", inex_pow_si);
exit (1);
}
}
mpc_clear (x);
mpc_clear (z);
mpc_clear (t);
}
mpc_clear (y);
gmp_randclear (state);
}
int
main (void)
{
test_start ();
compare_mpc_pow (100, 5, 19);
test_end ();
return 0;
}