summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2013-12-03 14:53:52 +0000
committerthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2013-12-03 14:53:52 +0000
commit548dc404ae08092db534923fbbb36220ed87abb1 (patch)
treec8e6260834bf08eca0ec1b8ae3c98159ee470c41
parent7f9cba1b38e3c8c9b4a3f24492dca26a2643df36 (diff)
downloadmpc-548dc404ae08092db534923fbbb36220ed87abb1.tar.gz
[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
-rw-r--r--tests/mpc-tests.h2
-rw-r--r--tests/random.c29
-rw-r--r--tests/tgeneric.tpl15
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 (&params->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: