diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-09-05 08:25:33 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-09-05 08:25:33 +0000 |
commit | 5f3039ca80f175e4c3e055b39d9e3f0f5a1236da (patch) | |
tree | 81ebb6763812c4b3fbd115c3a14e93e60f56e99c | |
parent | ac7303b2fea3b8e3b9accf0a175a01b4bf057f46 (diff) | |
download | mpfr-5f3039ca80f175e4c3e055b39d9e3f0f5a1236da.tar.gz |
[src/mpfr-mini-gmp.c] fixed gmp_urandomb_ui for 16-bit limb, added mpz_dump
[tests/terandom_chisq.c] more details in case of error
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13134 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/mpfr-mini-gmp.c | 56 | ||||
-rw-r--r-- | tests/terandom_chisq.c | 2 |
2 files changed, 57 insertions, 1 deletions
diff --git a/src/mpfr-mini-gmp.c b/src/mpfr-mini-gmp.c index 70677dcfa..f6143879d 100644 --- a/src/mpfr-mini-gmp.c +++ b/src/mpfr-mini-gmp.c @@ -106,7 +106,22 @@ gmp_urandomm_ui (gmp_randstate_t state, unsigned long n) unsigned long gmp_urandomb_ui (gmp_randstate_t state, unsigned long n) { +#ifdef MPFR_LONG_WITHIN_LIMB return random_limb () % (1UL << n); +#else + unsigned long res = 0; + int m = n; /* remaining bits to generate */ + while (m >= GMP_NUMB_BITS) + { + /* we can generate a full limb */ + res = (res << GMP_NUMB_BITS) | (unsigned long) random_limb (); + m -= GMP_NUMB_BITS; + } + /* now m < GMP_NUMB_BITS */ + if (m) /* generate m extra bits */ + res = (res << m) | (unsigned long) (random_limb () % (1UL << m)); + return res; +#endif } #endif @@ -210,4 +225,45 @@ mpn_tdiv_qr (mp_limb_t *qp, mp_limb_t *rp, mp_size_t qxn, } #endif +void +mpz_dump (mpz_t z) +{ + mp_size_t n = z->_mp_size; + + MPFR_STAT_STATIC_ASSERT ((GMP_NUMB_BITS % 4) == 0); + + if (n == 0) + printf ("0"); + else + { + int first = 1; + if (n < 0) + { + printf ("-"); + n = -n; + } + while (n > 0) + { + if (first) + { + printf ("%lx", z->_mp_d[n-1]); + first = 0; + } + else + { + char s[17]; + int len; + sprintf (s, "%lx", z->_mp_d[n-1]); + len = strlen (s); + /* one character should be printed for 4 bits */ + while (len++ < GMP_NUMB_BITS / 4) + printf ("0"); + printf ("%lx", z->_mp_d[n-1]); + } + n--; + } + } + printf ("\n"); +} + #endif /* MPFR_USE_MINI_GMP */ diff --git a/tests/terandom_chisq.c b/tests/terandom_chisq.c index 5d4e5109a..17419e035 100644 --- a/tests/terandom_chisq.c +++ b/tests/terandom_chisq.c @@ -311,7 +311,7 @@ run_chisq (double (*f)(long, mpfr_prec_t, int, double, double, int), else if (Q < Qbad) { printf ("Error: mpfr_erandom chi-squared failure " - "(prob = %.2e)\n", Q); + "(prob = %.2e < %.2e)\n", Q, Qbad); exit (1); } num *= 10; |