-/* random.c -- Handle seed for random numbers.
+/* Handle seed for random numbers.
-// Copyright (C) 2008, 2009, 2010, 2011 INRIA
+Copyright (C) 2008, 2009 Philippe Th\'eveny, Paul Zimmermann, Andreas Enge
-This file is part of GNU MPC.
+This file is part of the MPC Library.
-GNU MPC 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 3 of the License, or (at your
+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.
-GNU MPC 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.
+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 this program. If not, see http://www.gnu.org/licenses/ .
-*/
+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. */
/* Put test_start at the beginning of your test function and
test_end at the end.
These are an adaptation of those of MPFR. */
-#include "config.h"
#include <stdlib.h>
+
#include "mpc-tests.h"
+#include "config.h"
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
#endif
gmp_randstate_t rands;
-static char rands_initialized;
+char rands_initialized;
void
test_start (void)
char *environment_seed;
unsigned long seed;
+ tests_memory_start ();
+
if (rands_initialized)
{
fprintf (stderr,
gmp_randseed_ui (rands, 0xfac11e);
else
{
- seed = (unsigned long int) atoi (environment_seed);
+ seed = atoi (environment_seed);
if (seed == 0 || seed == 1)
{
-#if defined HAVE_GETTIMEOFDAY
+#if HAVE_GETTIMEOFDAY
struct timeval tv;
gettimeofday (&tv, NULL);
- seed = (unsigned long int) (tv.tv_sec + tv.tv_usec);
+ seed = tv.tv_sec + tv.tv_usec;
#else
time_t tv;
time (&tv);
- seed = (unsigned long int) tv;
+ seed = tv;
#endif
gmp_randseed_ui (rands, seed);
printf ("Seed GMP_CHECK_RANDOMIZE=%lu "
gmp_randclear (rands);
}
mpfr_free_cache ();
+ tests_memory_end ();
}
/* Set z to a non zero value random value with absolute values of Re(z) and
equal to ZERO_PROBABILITY / 256.
*/
void
-test_default_random (mpc_ptr z, mpfr_exp_t emin, mpfr_exp_t emax,
+test_default_random (mpc_ptr z, mp_exp_t emin, mp_exp_t emax,
unsigned int negative_probability,
unsigned int zero_probability)
{
- const unsigned long range = (unsigned long int) (emax - emin) + 1;
+ const unsigned long range = (long)emax - (long)emin + 1;
unsigned long r;
if (!rands_initialized)
do
{
mpc_urandom (z, rands);
- } while (mpfr_zero_p (mpc_realref (z)) || mpfr_zero_p (mpc_imagref (z)));
+ } while (mpfr_zero_p (MPC_RE (z)) || mpfr_zero_p (MPC_IM (z)));
if (zero_probability > 256)
zero_probability = 256;
zero_im_p = !zero_re_p;
}
if (zero_re_p)
- mpfr_set_ui (mpc_realref (z), 0, GMP_RNDN);
+ mpfr_set_ui (MPC_RE (z), 0, GMP_RNDN);
if (zero_im_p)
- mpfr_set_ui (mpc_imagref (z), 0, GMP_RNDN);
+ mpfr_set_ui (MPC_IM (z), 0, GMP_RNDN);
}
- if (!mpfr_zero_p (mpc_realref (z)))
- mpfr_set_exp (mpc_realref (z), (mpfr_exp_t) gmp_urandomm_ui (rands, range) + emin);
+ if (!mpfr_zero_p (MPC_RE (z)))
+ mpfr_set_exp (MPC_RE (z), (mp_exp_t) gmp_urandomm_ui (rands, range) + emin);
- if (!mpfr_zero_p (mpc_imagref (z)))
- mpfr_set_exp (mpc_imagref (z), (mpfr_exp_t) gmp_urandomm_ui (rands, range) + emin);
+ if (!mpfr_zero_p (MPC_IM (z)))
+ mpfr_set_exp (MPC_IM (z), (mp_exp_t) gmp_urandomm_ui (rands, range) + emin);
if (negative_probability > 256)
negative_probability = 256;
r = gmp_urandomb_ui (rands, 16);
if ((r & 0xFF) < negative_probability)
- mpfr_neg (mpc_realref (z), mpc_realref (z), GMP_RNDN);
+ mpfr_neg (MPC_RE (z), MPC_RE (z), GMP_RNDN);
if (((r>>8) & 0xFF) < negative_probability)
- mpfr_neg (mpc_imagref (z), mpc_imagref (z), GMP_RNDN);
+ mpfr_neg (MPC_IM (z), MPC_IM (z), GMP_RNDN);
}