summaryrefslogtreecommitdiff
path: root/src/add1sp.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2017-12-17 16:23:21 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2017-12-17 16:23:21 +0000
commitb67679a0309d4968fc02807bf42c6d1cd427740d (patch)
tree8a14ea54637a59eb0e7a3f3216ccbbf0e51f5e90 /src/add1sp.c
parent53573c762974dc7d43fd466d07d2cb55651d175f (diff)
downloadmpfr-b67679a0309d4968fc02807bf42c6d1cd427740d.tar.gz
[src/add1sp.c] fix bug in mpfr_add1sp3() in case d=GMP_NUMB_BITS
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11987 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/add1sp.c')
-rw-r--r--src/add1sp.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/add1sp.c b/src/add1sp.c
index 3d37b87ea..3dee9df79 100644
--- a/src/add1sp.c
+++ b/src/add1sp.c
@@ -527,7 +527,11 @@ mpfr_add1sp3 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode,
: (cp[2] << (2*GMP_NUMB_BITS-d)) | (cp[1] >> (d - GMP_NUMB_BITS));
a0 = bp[0] + c0shifted;
a1 = bp[1] + (cp[2] >> (d - GMP_NUMB_BITS)) + (a0 < bp[0]);
- a2 = bp[2] + (a1 < bp[1]);
+ /* if a1 < bp[1], there was a carry in the above addition,
+ or when a1 = bp[1] and one of the added terms is nonzero
+ (the sum of cp[2] >> (d - GMP_NUMB_BITS) and a0 < bp[0]
+ is at most 2^GMP_NUMB_BITS-d) */
+ a2 = bp[2] + ((a1 < bp[1]) || (a1 == bp[1] && a0 < bp[0]));
if (a2 == 0)
goto exponent_shift;
rb = a0 & (MPFR_LIMB_ONE << (sh - 1));