diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-08-29 12:17:13 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-08-29 12:17:13 +0000 |
commit | 7ae9ac24e27e621a4b428bb55aa35e47ca94de48 (patch) | |
tree | 203965a5e94a610484266dacfc9dba20d660e2e1 | |
parent | 6752f3e43419a3137f15d6b2b76f3c3c63bd35ba (diff) | |
download | mpfr-7ae9ac24e27e621a4b428bb55aa35e47ca94de48.tar.gz |
[src/urandom.c] Clarified a comment about a subtle case.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@11689 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/urandom.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/urandom.c b/src/urandom.c index 0283bdccb..a30f9a843 100644 --- a/src/urandom.c +++ b/src/urandom.c @@ -120,10 +120,16 @@ mpfr_urandom (mpfr_ptr rop, gmp_randstate_t rstate, mpfr_rnd_t rnd_mode) in a row, then return 0 or the smallest representable positive number. - The rounding to nearest mode is subtle: - 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. */ + The rounding-to-nearest mode is subtle: We need to round to + the smallest representable positive number iff the exponent + is emin - 1. This condition can be satisfied only if the + current emin is emin - 1. In this case, if cnt != DRAW_BITS, + this in the final emin, so that the condition is satisfied. + But if cnt == DRAW_BITS, we need to draw an additional bit + to determine whether emin == emin - 1 or emin < emin - 1 + (with equal probabilities); the reason is that we return + just below instead of doing more iterations in the "while" + loop to find the final value of emin. */ __gmpfr_flags |= MPFR_FLAGS_UNDERFLOW; if (rnd_mode == MPFR_RNDU || rnd_mode == MPFR_RNDA || (rnd_mode == MPFR_RNDN && exp == __gmpfr_emin - 1 |