diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-07-07 09:49:04 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-07-07 09:49:04 +0000 |
commit | 0681662f2ade298561c345a87232d24d12aaee21 (patch) | |
tree | ca468a667cc1d9e159aa3cc9776e1afafa06cf7a /random.c | |
parent | d589e227104252c12f7058c55677f051bb361ebc (diff) | |
download | mpfr-0681662f2ade298561c345a87232d24d12aaee21.tar.gz |
simply set to zero the non-significant bits, don't call mpfr_round_raw
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@341 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'random.c')
-rw-r--r-- | random.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -24,12 +24,12 @@ mpfr_random(x) mpfr_ptr x; #endif { - mp_limb_t *xp; unsigned long xs, i, cnt; + mp_limb_t *xp; unsigned long xn, i, cnt, prec=PREC(x); - xp = MANT(x); - xs = ABSSIZE(x); + xp = MANT(x); + xn = (prec-1)/BITS_PER_MP_LIMB + 1; - for (i = 0; i < xs; i++) + for (i = 0; i < xn; i++) { /* random() c/sh/ould be replaced by a homemade random number generator. Indeed, if on Linux random is a good RNG, this is definitely not @@ -37,11 +37,13 @@ mpfr_random(x) xp[i] = random(); } - count_leading_zeros(cnt, xp[xs - 1]); - if (cnt) mpn_lshift(xp, xp, xs, cnt); + count_leading_zeros(cnt, xp[xn - 1]); + if (cnt) mpn_lshift(xp, xp, xn, cnt); EXP(x) = -cnt; - mpfr_round_raw(xp, xp, PREC(x), (SIGN(x)<0), PREC(x), random()&3); - /* ignore any possible carry (this is sheer laziness). */ + + cnt = xn*BITS_PER_MP_LIMB - prec; + /* cnt is the number of non significant bits in the low limb */ + xp[0] &= ~((((mp_limb_t)1)<<cnt) - 1); } void |