summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-09-04 14:50:57 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-09-04 14:50:57 +0000
commit4e9af690f7589ba1e17e07cd5a6de6f2c25e1188 (patch)
tree44bd050dd6bca294aef5e564a02861eb0dec393f
parentbc437ed852b783752a801b87601de1690ce2aa6f (diff)
downloadmpfr-4e9af690f7589ba1e17e07cd5a6de6f2c25e1188.tar.gz
[tests/tset_z_exp.c] fixed infinite loop in test code for limb < mpfr_exp_t
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13127 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--tests/tset_z_exp.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/tset_z_exp.c b/tests/tset_z_exp.c
index cd3818cf3..18c80951f 100644
--- a/tests/tset_z_exp.c
+++ b/tests/tset_z_exp.c
@@ -22,11 +22,24 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-test.h"
+/* generate a random exponent in [__gmpfr_emin, __gmpfr_emax-1] */
static mpfr_exp_t
randexp (void)
{
+#if defined(MPFR_LONG_WITHIN_LIMB) && _MPFR_EXP_FORMAT <= 3
+ /* if _MPFR_EXP_FORMAT <= 3, mpfr_exp_t <= long, thus since a long fits in
+ a limb, we can generate the whole range [emin, emax] */
return (mpfr_exp_t) (randlimb () % (__gmpfr_emax - __gmpfr_emin))
+ __gmpfr_emin;
+#else
+ mpfr_exp_t emax = MPFR_EMAX_MAX, e = 0;
+ while (emax != 0)
+ {
+ e = (e << GMP_NUMB_BITS) + randlimb ();
+ emax >>= GMP_NUMB_BITS;
+ }
+ return (mpfr_exp_t) e % (__gmpfr_emax - __gmpfr_emin) + __gmpfr_emin;
+#endif
}
static void