summaryrefslogtreecommitdiff
path: root/tests/random.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-03-27 10:23:32 +0000
committerzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-03-27 10:23:32 +0000
commit5c9187b52336154d3cb5195f45b99c80e5097d24 (patch)
tree8a190343aae977bc4ef3dacf964f96e38f1212ac /tests/random.c
parentd8d8a0e6caf163cbffa9d1f2beb4c6c7d2e2bdb9 (diff)
downloadmpc-5c9187b52336154d3cb5195f45b99c80e5097d24.tar.gz
[configure.ac] minimal GMP version is now 4.1.3 instead of 4.2
[mem.c] new wrapper file for mp_get_memory_functions (not in GMP 4.1.3) [get_str.c,inp_str.c] moved mp_get_memory_functions to mem.c [tests/tset.c,tests/random.c] added wrappers for gmp_random functions (not in GMP 4.1.3) git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@509 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'tests/random.c')
-rw-r--r--tests/random.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/tests/random.c b/tests/random.c
index 75c661f..a28c464 100644
--- a/tests/random.c
+++ b/tests/random.c
@@ -1,6 +1,6 @@
/* Handle seed for random numbers.
-Copyright (C) 2008, 2009 Philippe Th\'eveny.
+Copyright (C) 2008, 2009 Philippe Th\'eveny, Paul Zimmermann
This file is part of the MPC Library.
@@ -98,6 +98,45 @@ test_end (void)
}
}
+/* wrapper for gmp_urandomb_ui, which did not exist in old versions of GMP */
+static unsigned long
+urandomb_ui (unsigned long N)
+{
+#ifdef gmp_urandomb_ui /* does not exist in GMP 4.1.4 */
+ return gmp_urandomb_ui (rands, N);
+#else
+ mpz_t R;
+ unsigned long r;
+ mpz_init (R);
+ mpz_urandomb (R, rands, N);
+ r = mpz_get_ui (R);
+ mpz_clear (R);
+ return r;
+#endif
+}
+
+/* wrapper for gmp_urandomm_ui, which did not exist in old versions of GMP */
+unsigned long
+urandomm_ui (unsigned long N)
+{
+#ifdef gmp_urandomm_ui /* does not exist in GMP 4.1.4 */
+ return gmp_urandomm_ui (rands, N);
+#else
+ mpz_t R, S;
+ unsigned long r;
+ mpz_init_set_ui (S, N);
+ mpz_init (R);
+ /* there was a bug in mpz_urandomm up to GMP 4.2.4, when the 1st and 3rd
+ argument were the same */
+ mpz_urandomm (R, rands, S);
+ r = mpz_get_ui (R);
+ mpz_clear (R);
+ mpz_clear (S);
+ return r;
+#endif
+}
+
+
/* Set z to a non zero value random value with absolute values of Re(z) and
Im(z) either zero (but not both in the same time) or otherwise greater than
or equal to 2^{emin-1} and less than 2^emax.
@@ -127,7 +166,7 @@ test_default_random (mpc_ptr z, mp_exp_t emin, mp_exp_t emax,
if (zero_probability > 256)
zero_probability = 256;
- r = gmp_urandomb_ui (rands, 19);
+ r = urandomb_ui (19);
if ((r & 0x1FF) < zero_probability
|| ((r >> 9) & 0x1FF) < zero_probability)
{
@@ -146,16 +185,14 @@ test_default_random (mpc_ptr z, mp_exp_t emin, mp_exp_t emax,
mpfr_set_ui (MPC_IM (z), 0, GMP_RNDN);
}
if (!mpfr_zero_p (MPC_RE (z)))
- mpfr_set_exp (MPC_RE (z),
- (mp_exp_t) gmp_urandomm_ui (rands, range) + emin);
+ mpfr_set_exp (MPC_RE (z), (mp_exp_t) urandomm_ui (range) + emin);
if (!mpfr_zero_p (MPC_IM (z)))
- mpfr_set_exp (MPC_IM (z),
- (mp_exp_t) gmp_urandomm_ui (rands, range) + emin);
+ mpfr_set_exp (MPC_IM (z), (mp_exp_t) urandomm_ui (range) + emin);
if (negative_probability > 256)
negative_probability = 256;
- r = gmp_urandomb_ui (rands, 16);
+ r = urandomb_ui (16);
if ((r & 0xFF) < negative_probability)
mpfr_neg (MPC_RE (z), MPC_RE (z), GMP_RNDN);
if (((r>>8) & 0xFF) < negative_probability)