diff options
author | thevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4> | 2009-03-24 16:51:17 +0000 |
---|---|---|
committer | thevenyp <thevenyp@280ebfd0-de03-0410-8827-d642c229c3f4> | 2009-03-24 16:51:17 +0000 |
commit | 92dc794c8665060ccf30421943920fb188c10f02 (patch) | |
tree | 2eec5980f13d695baa5fee0fc2eb994279559b35 | |
parent | 49406a145c30997c8c82d33696e2b3b1de930e0f (diff) | |
download | mpfr-92dc794c8665060ccf30421943920fb188c10f02.tar.gz |
urandomb.c mpfr-gmp.c mpfr-gmp.h: mpfr_rand_raw is now in urandom.c.
mpfr-impl.h: mpfr_rand_raw is now always build as an internal function.
TODO tests/tests.c tests/random2.c: Use mpfr_rand_raw instead of _gmp_rand
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@6137 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | mpfr-gmp.c | 11 | ||||
-rw-r--r-- | mpfr-gmp.h | 5 | ||||
-rw-r--r-- | mpfr-impl.h | 3 | ||||
-rw-r--r-- | tests/random2.c | 6 | ||||
-rw-r--r-- | tests/tests.c | 2 | ||||
-rw-r--r-- | urandomb.c | 13 |
7 files changed, 19 insertions, 23 deletions
@@ -87,8 +87,6 @@ Table of contents: aa = q*b+r --> q has exaclty n bits. If RNDN, takes nq+1 bits. (See also the new division function). -- random functions: get rid of _gmp_rand. - ############################################################################## 4. New functions to implement diff --git a/mpfr-gmp.c b/mpfr-gmp.c index 439a6a194..c4faa7352 100644 --- a/mpfr-gmp.c +++ b/mpfr-gmp.c @@ -305,17 +305,6 @@ mpfr_assert_fail (const char *filename, int linenum, abort(); } -void -mpfr_rand_raw (mp_ptr mp, gmp_randstate_t rstate, unsigned long int nbits) -{ - mpz_t z; - - /* To be sure to avoid the potential allocation of mpz_urandomb */ - ALLOC(z) = SIZ(z) = (nbits / GMP_NUMB_BITS) + 1; - PTR(z) = mp; - mpz_urandomb(z, rstate, nbits); -} - #ifdef mp_get_memory_functions /* putting 0 as initial values forces those symbols to be fully defined, diff --git a/mpfr-gmp.h b/mpfr-gmp.h index 8c5bc50c3..fec21dd4e 100644 --- a/mpfr-gmp.h +++ b/mpfr-gmp.h @@ -253,11 +253,6 @@ __MPFR_DECLSPEC extern gmp_randstate_t mpfr_rands; typedef __gmp_randstate_struct *gmp_randstate_ptr; -#undef _gmp_rand -#define _gmp_rand mpfr_rand_raw -__MPFR_DECLSPEC void mpfr_rand_raw _MPFR_PROTO((mp_ptr, gmp_randstate_t, - unsigned long)); - /* Allocate func are defined in gmp-impl.h */ /* In newer GMP, there aren't anymore __gmp_allocate_func, diff --git a/mpfr-impl.h b/mpfr-impl.h index 4643b32ae..4b6a421cc 100644 --- a/mpfr-impl.h +++ b/mpfr-impl.h @@ -1675,6 +1675,9 @@ __MPFR_DECLSPEC int mpfr_round_near_x _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, __MPFR_DECLSPEC void mpfr_abort_prec_max _MPFR_PROTO ((void)) MPFR_NORETURN_ATTR; +__MPFR_DECLSPEC void mpfr_rand_raw _MPFR_PROTO((mp_ptr, gmp_randstate_t, + unsigned long)); + #if defined (__cplusplus) } #endif diff --git a/tests/random2.c b/tests/random2.c index 66739e862..5b769295a 100644 --- a/tests/random2.c +++ b/tests/random2.c @@ -68,7 +68,7 @@ mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp, /* Code extracted from GMP, function mpn_random2, to avoid the use of GMP's internal random state in MPFR */ - _gmp_rand (&elimb, rstate, BITS_PER_RANDCALL); + mpfr_rand_raw (&elimb, rstate, BITS_PER_RANDCALL); ran = elimb; /* Start off at a random bit position in the most significant limb. */ @@ -86,7 +86,7 @@ mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp, { if (ran_nbits < LOGBITS_PER_BLOCK + 1) { - _gmp_rand (&elimb, rstate, BITS_PER_RANDCALL); + mpfr_rand_raw (&elimb, rstate, BITS_PER_RANDCALL); ran = elimb; ran_nbits = BITS_PER_RANDCALL; } @@ -139,7 +139,7 @@ mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp, } /* Generate random exponent. */ - _gmp_rand (&elimb, RANDS, BITS_PER_MP_LIMB); + mpfr_rand_raw (&elimb, RANDS, BITS_PER_MP_LIMB); exp = ABS (exp); MPFR_SET_EXP (x, elimb % (2 * exp + 1) - exp); diff --git a/tests/tests.c b/tests/tests.c index ae2903524..82843b8fc 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -336,7 +336,7 @@ randlimb (void) { mp_limb_t limb; - _gmp_rand (&limb, RANDS, BITS_PER_MP_LIMB); + mpfr_rand_raw (&limb, RANDS, BITS_PER_MP_LIMB); return limb; } diff --git a/urandomb.c b/urandomb.c index d42d09801..ed6dd95db 100644 --- a/urandomb.c +++ b/urandomb.c @@ -27,6 +27,17 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define MPFR_NEED_LONGLONG_H #include "mpfr-impl.h" +void +mpfr_rand_raw (mp_ptr mp, gmp_randstate_t rstate, unsigned long int nbits) +{ + mpz_t z; + + /* To be sure to avoid the potential allocation of mpz_urandomb */ + ALLOC(z) = SIZ(z) = (nbits / GMP_NUMB_BITS) + 1; + PTR(z) = mp; + mpz_urandomb(z, rstate, nbits); +} + int mpfr_urandomb (mpfr_ptr rop, gmp_randstate_t rstate) { @@ -45,7 +56,7 @@ mpfr_urandomb (mpfr_ptr rop, gmp_randstate_t rstate) MPFR_SET_POS (rop); /* Uniform non-normalized significand */ - _gmp_rand (rp, rstate, nlimbs * BITS_PER_MP_LIMB); + mpfr_rand_raw (rp, rstate, nlimbs * BITS_PER_MP_LIMB); /* If nbits isn't a multiple of BITS_PER_MP_LIMB, mask the low bits */ cnt = nlimbs * BITS_PER_MP_LIMB - nbits; |