diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-06-17 05:41:36 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-06-17 05:41:36 +0000 |
commit | 7fd0c4a63c0f9abd6c346594fb2d771d3b470c17 (patch) | |
tree | e79c12c4a427012b598e0641da3f2898a46acd33 /src/random_deviate.c | |
parent | 1b19d74ed07c8c46c1df0668bf4be8e914bd5226 (diff) | |
download | mpfr-7fd0c4a63c0f9abd6c346594fb2d771d3b470c17.tar.gz |
patches from Charles Karney
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9066 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/random_deviate.c')
-rw-r--r-- | src/random_deviate.c | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/src/random_deviate.c b/src/random_deviate.c index fbb020bd2..5bfc96cbe 100644 --- a/src/random_deviate.c +++ b/src/random_deviate.c @@ -380,38 +380,14 @@ mpfr_random_deviate_value (int neg, unsigned long n, if (neg) mpz_neg (t, t); /* Is -x->e representable as a mpfr_exp_t? */ - if (x->e <= (mpfr_uexp_t)(-1) >> 1) - { - /* - * Let mpfr_set_z_2exp do all the work of rounding to the requested - * precision, setting overflow/underflow flags, and returning the right - * inexact value. - */ - inex = mpfr_set_z_2exp (z, t, -x->e, rnd); - mpz_clear (t); - } - else - { - /* - * Cannot convert to mpfr in a single call to mpfr_set_z_2exp because the - * shift is too big (implies that the number of leading zeros in the - * fraction and the requested precision are both large). So form an - * rational number q = t/2^(x->e) and convert that. - */ - mpq_t q; - mpz_ptr qn, qd; - mpq_init (q); /* q = 0/1 */ - qn = mpq_numref(q); - mpz_swap (qn, t); /* numerator = t */ - mpz_clear (t); - qd = mpq_denref(q); /* initially equal to 1 */ - /* we know that x->e fits into a mp_bitcnt_t */ - mpz_mul_2exp (qd, qd, x->e); /* denominator = 2^(x->e) */ - /* no need to call mpq_canonicalize because qn is odd and qd is - * positive and a power of 2 */ - inex = mpfr_set_q (z, q, rnd); - mpq_clear (q); - } + MPFR_ASSERTN (x->e <= (mpfr_uexp_t)(-1) >> 1); + /* + * Let mpfr_set_z_2exp do all the work of rounding to the requested + * precision, setting overflow/underflow flags, and returning the right + * inexact value. + */ + inex = mpfr_set_z_2exp (z, t, -x->e, rnd); + mpz_clear (t); return inex; } #endif |