summaryrefslogtreecommitdiff
path: root/src/next.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2014-02-12 02:13:50 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2014-02-12 02:13:50 +0000
commitb7dbdfffd2c0c8aadb30bc121600b05e0b292747 (patch)
treeba53b890a4ed09608162211a4e1a85c4cbeca6d2 /src/next.c
parent4dd547f86705f4fbde81388d3dab477241a4ccd4 (diff)
downloadmpfr-b7dbdfffd2c0c8aadb30bc121600b05e0b292747.tar.gz
[src/next.c] Improved handling of special values.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@8952 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/next.c')
-rw-r--r--src/next.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/next.c b/src/next.c
index c6ff1d891..dbf86dc28 100644
--- a/src/next.c
+++ b/src/next.c
@@ -26,15 +26,18 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
void
mpfr_nexttozero (mpfr_ptr x)
{
- if (MPFR_UNLIKELY(MPFR_IS_INF(x)))
+ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
{
- mpfr_setmax (x, __gmpfr_emax);
- return;
- }
- else if (MPFR_UNLIKELY( MPFR_IS_ZERO(x) ))
- {
- MPFR_CHANGE_SIGN(x);
- mpfr_setmin (x, __gmpfr_emin);
+ if (MPFR_IS_INF (x))
+ {
+ mpfr_setmax (x, __gmpfr_emax);
+ }
+ else
+ {
+ MPFR_ASSERTN (MPFR_IS_ZERO (x));
+ MPFR_CHANGE_SIGN(x);
+ mpfr_setmin (x, __gmpfr_emin);
+ }
}
else
{
@@ -46,10 +49,11 @@ mpfr_nexttozero (mpfr_ptr x)
MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC(x));
xp = MPFR_MANT(x);
mpn_sub_1 (xp, xp, xn, MPFR_LIMB_ONE << sh);
- if (MPFR_UNLIKELY( MPFR_LIMB_MSB(xp[xn-1]) == 0) )
- { /* was an exact power of two: not normalized any more */
+ if (MPFR_UNLIKELY (MPFR_LIMB_MSB (xp[xn-1]) == 0))
+ { /* was an exact power of two: not normalized any more,
+ thus do not use MPFR_GET_EXP. */
mpfr_exp_t exp = MPFR_EXP (x);
- if (MPFR_UNLIKELY(exp == __gmpfr_emin))
+ if (MPFR_UNLIKELY (exp == __gmpfr_emin))
MPFR_SET_ZERO(x);
else
{
@@ -66,10 +70,11 @@ mpfr_nexttozero (mpfr_ptr x)
void
mpfr_nexttoinf (mpfr_ptr x)
{
- if (MPFR_UNLIKELY(MPFR_IS_INF(x)))
- return;
- else if (MPFR_UNLIKELY(MPFR_IS_ZERO(x)))
- mpfr_setmin (x, __gmpfr_emin);
+ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
+ {
+ if (MPFR_IS_ZERO (x))
+ mpfr_setmin (x, __gmpfr_emin);
+ }
else
{
mp_size_t xn;
@@ -79,12 +84,12 @@ mpfr_nexttoinf (mpfr_ptr x)
xn = MPFR_LIMB_SIZE (x);
MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC(x));
xp = MPFR_MANT(x);
- if (MPFR_UNLIKELY( mpn_add_1 (xp, xp, xn, MPFR_LIMB_ONE << sh)) )
+ if (MPFR_UNLIKELY (mpn_add_1 (xp, xp, xn, MPFR_LIMB_ONE << sh)))
/* got 1.0000... */
{
mpfr_exp_t exp = MPFR_EXP (x);
- if (MPFR_UNLIKELY(exp == __gmpfr_emax))
- MPFR_SET_INF(x);
+ if (MPFR_UNLIKELY (exp == __gmpfr_emax))
+ MPFR_SET_INF (x);
else
{
MPFR_SET_EXP (x, exp + 1);