From 548dc404ae08092db534923fbbb36220ed87abb1 Mon Sep 17 00:00:00 2001 From: thevenyp Date: Tue, 3 Dec 2013 14:53:52 +0000 Subject: [tests/] Add random generators for integer parameters. git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/branches/benchs_tests@1362 211d60ee-9f03-0410-a15a-8952a2c7a4e4 --- tests/mpc-tests.h | 2 ++ tests/random.c | 29 +++++++++++++++++++++++++++++ tests/tgeneric.tpl | 15 +++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/tests/mpc-tests.h b/tests/mpc-tests.h index c1864de..1b43361 100644 --- a/tests/mpc-tests.h +++ b/tests/mpc-tests.h @@ -107,6 +107,8 @@ extern void test_end (void); extern void test_default_random (mpc_ptr, mp_exp_t, mp_exp_t, unsigned int, unsigned int); +void test_random_si (long int *n, unsigned long emax, + unsigned int negative_probability); void test_random_mpfr (mpfr_ptr x, mpfr_exp_t emin, mpfr_exp_t emax, unsigned int negative_probability); void test_random_mpc (mpc_ptr z, mpfr_exp_t emin, mpfr_exp_t emax, diff --git a/tests/random.c b/tests/random.c index 5fb7adf..0420f66 100644 --- a/tests/random.c +++ b/tests/random.c @@ -159,6 +159,35 @@ test_default_random (mpc_ptr z, mpfr_exp_t emin, mpfr_exp_t emax, mpfr_neg (mpc_imagref (z), mpc_imagref (z), MPFR_RNDN); } +/* Set n to a non zero value random value with absolute values less than + 2^emax. + + n is negative with probability equal to NEGATIVE_PROBABILITY / 256. +*/ +void test_random_si (long int *n, unsigned long emax, + unsigned int negative_probability) +{ + unsigned long r; + + if (!rands_initialized) + { + fprintf (stderr, + "Put test_start at the beginning of your test function.\n"); + exit (1); + } + + do + { + *n = gmp_urandomb_ui (rands, emax); + } while (*n == 0); + + if (negative_probability > 256) + negative_probability = 256; + r = gmp_urandomb_ui (rands, 8); + if ((r & 0xFF) < negative_probability) + *n = -(*n); +} + /* Set x to a non zero value random value with absolute values greater than or equal to 2^{emin-1} and less than 2^emax. diff --git a/tests/tgeneric.tpl b/tests/tgeneric.tpl index 1ce8079..1525abb 100644 --- a/tests/tgeneric.tpl +++ b/tests/tgeneric.tpl @@ -237,14 +237,25 @@ random_params (mpc_fun_param_t *params, const int start = params->nbout; const int end = start + params->nbin - 1; /* the last input parameter is the rounding mode */ + const unsigned int int_emax = 63; /* maximum binary exponent for random + integer */ + for (i = start; i < end; i++) { + long int si; switch (params->T[i]) { case NATIVE_INT: - case NATIVE_UL: case NATIVE_L: - /* TODO: draw random value */ + test_random_si (&si, int_emax, 128); + params->P[i].i = (int) si; + break; + case NATIVE_L: + test_random_si (¶ms->P[i].si, int_emax, 128); + break; + case NATIVE_UL: + test_random_si (&si, int_emax, 0); + params->P[i].ui = (unsigned long)si; break; case NATIVE_D: case NATIVE_LD: -- cgit v1.2.1