diff options
Diffstat (limited to 'src/urandom.c')
-rw-r--r-- | src/urandom.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/urandom.c b/src/urandom.c index 8ca5f043e..0145be52c 100644 --- a/src/urandom.c +++ b/src/urandom.c @@ -87,19 +87,20 @@ mpfr_urandom (mpfr_ptr rop, gmp_randstate_t rstate, mpfr_rnd_t rnd_mode) count_leading_zeros (cnt, rp[0]); cnt -= GMP_NUMB_BITS - DRAW_BITS; } + exp -= cnt; /* no integer overflow */ - if (MPFR_UNLIKELY (exp < emin + cnt)) + if (MPFR_UNLIKELY (exp < emin)) { /* To get here, we have been drawing more than -emin zeros in a row, then return 0 or the smallest representable positive number. The rounding to nearest mode is subtle: - If exp - cnt == emin - 1, the rounding bit is set, except + If exp == emin - 1, the rounding bit is set, except if cnt == DRAW_BITS in which case the rounding bit is outside rp[0] and must be generated. */ if (rnd_mode == MPFR_RNDU || rnd_mode == MPFR_RNDA - || (rnd_mode == MPFR_RNDN && cnt == exp - emin - 1 + || (rnd_mode == MPFR_RNDN && exp == emin - 1 && (cnt != DRAW_BITS || random_rounding_bit (rstate)))) { mpfr_set_ui_2exp (rop, 1, emin - 1, rnd_mode); @@ -111,7 +112,6 @@ mpfr_urandom (mpfr_ptr rop, gmp_randstate_t rstate, mpfr_rnd_t rnd_mode) return -1; } } - exp -= cnt; } MPFR_EXP (rop) = exp; /* Warning: may be outside the current exponent range */ |