summaryrefslogtreecommitdiff
path: root/src/sub1.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-02-11 12:22:29 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-02-11 12:22:29 +0000
commitadca15f4321606f21c681579829f6929aa37561a (patch)
treef31b796cae34e07a1753c7ae225fdd6fe06e26a7 /src/sub1.c
parent7653db3b9128c7bd5b50f42c8b7fbdf6a27acdb1 (diff)
downloadmpfr-adca15f4321606f21c681579829f6929aa37561a.tar.gz
[tests/tfmma.c] Merged the latest tests from the trunk
(r12752,12759,13688,13696). [src/sub1.c] Bug fix: the underflow case (possible with UBF, e.g. via mpfr_fmma or mpfr_fmms) was not tested in the case c small. (merged changeset r13694 from the trunk) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@13697 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/sub1.c')
-rw-r--r--src/sub1.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/sub1.c b/src/sub1.c
index 9337cc235..5b475d9d3 100644
--- a/src/sub1.c
+++ b/src/sub1.c
@@ -123,11 +123,11 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode)
if (rnd_mode == MPFR_RNDF)
return mpfr_set4 (a, b, MPFR_RNDZ, MPFR_SIGN (a));
- MPFR_EXP (a) = exp_b; /* may be up to MPFR_EXP_MAX */
+ exp_a = exp_b; /* may be any out-of-range value due to UBF */
MPFR_RNDRAW_EVEN (inexact, a, MPFR_MANT (b), bq,
rnd_mode, MPFR_SIGN (a),
- if (MPFR_EXP (a) != MPFR_EXP_MAX)
- ++ MPFR_EXP (a));
+ if (exp_a != MPFR_EXP_MAX)
+ exp_a ++);
MPFR_LOG_MSG (("inexact=%d\n", inexact));
if (inexact == 0)
{
@@ -139,7 +139,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode)
if (! MPFR_IS_LIKE_RNDZ (rnd_mode, MPFR_IS_NEG (a)))
{
inexact = MPFR_INT_SIGN (a);
- goto check_overflow;
+ goto end_of_c_small;
}
}
else /* inexact != 0 */
@@ -164,7 +164,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode)
which means we get a wrong rounded result if x == 1,
i.e. inexact == MPFR_EVEN_INEX (for positive numbers). */
if (MPFR_LIKELY (inexact != MPFR_EVEN_INEX * MPFR_INT_SIGN (a)))
- goto check_overflow;
+ goto end_of_c_small;
}
/* We need to take the value preceding |a|. We can't use
mpfr_nexttozero due to a possible out-of-range exponent.
@@ -174,16 +174,20 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode)
mpn_sub_1 (ap, ap, an, MPFR_LIMB_ONE << sh);
if (MPFR_UNLIKELY (MPFR_LIMB_MSB (ap[an-1]) == 0))
{
- MPFR_EXP (a) --;
+ exp_a --;
/* The following is valid whether an = 1 or an > 1. */
ap[an-1] |= MPFR_LIMB_HIGHBIT;
}
inexact = - MPFR_INT_SIGN (a);
- check_overflow:
- if (MPFR_UNLIKELY (MPFR_EXP (a) > __gmpfr_emax))
+ end_of_c_small:
+ /* The underflow case is possibly only with UBF. The overflow case
+ is also possible with normal FP due to rounding. */
+ if (MPFR_UNLIKELY (exp_a > __gmpfr_emax))
return mpfr_overflow (a, rnd_mode, MPFR_SIGN (a));
- else
- MPFR_RET (inexact);
+ if (MPFR_UNLIKELY (exp_a < __gmpfr_emin))
+ goto underflow;
+ MPFR_SET_EXP (a, exp_a);
+ MPFR_RET (inexact);
}
/* reserve a space to store b aligned with the result, i.e. shifted by