diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-02-16 13:50:07 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-02-16 13:50:07 +0000 |
commit | 3022b32f72847fd540631afee1ebedbb1d26f1b1 (patch) | |
tree | 4c49207e44150807678e72a8c26043c9a2280ac5 /src/div_2ui.c | |
parent | 6884a446b800d13097e7e8f3939027f6892bd1af (diff) | |
download | mpfr-3022b32f72847fd540631afee1ebedbb1d26f1b1.tar.gz |
[src/div_2ui.c] Simplified code as suggested by PZ; added justification.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12268 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/div_2ui.c')
-rw-r--r-- | src/div_2ui.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/div_2ui.c b/src/div_2ui.c index c13ee883b..2d932f1f6 100644 --- a/src/div_2ui.c +++ b/src/div_2ui.c @@ -50,18 +50,11 @@ mpfr_div_2ui (mpfr_ptr y, mpfr_srcptr x, unsigned long n, mpfr_rnd_t rnd_mode) rnd_mode = MPFR_RNDZ; return mpfr_underflow (y, rnd_mode, MPFR_SIGN (y)); } - /* exp - n >= emin (no underflow, no integer overflow) */ - /* Since n is an unsigned long, n can be up to - 2 * LONG_MAX + 1 (mathematically). - Note: on a 64-bit computer, since emax <= 2^62-1 and emin >= 1-2^62, - we have diffexp <= 2^63-1, thus since here n < diffexp we have - n < 2^63-1, and the test n > LONG_MAX is never true. */ - while (n > LONG_MAX) - { - n -= LONG_MAX; - exp -= LONG_MAX; /* note: signed values */ - } - MPFR_SET_EXP (y, exp - (long) n); + /* Now, exp - n >= emin. Thus n <= exp - emin, which a + * difference of two valid exponents, thus fits in a mpfr_exp_t + * (from the constraints on valid exponents). + */ + MPFR_SET_EXP (y, exp - (mpfr_exp_t) n); } MPFR_RET (inexact); |