This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix determination of lower precision in __mul


Hi,

I introduced a dormant buglet when I committed the patch that skips
multiplication of zeroes.  The loop to determine the lower precision
of the two input numbers is buggy since it checks X[i] * Y[i] to be
non-zero to ensure that both mantissa digits are non-zero.  This is a
wrong check though since we could have numbers that have mantissa as
such:

X = {1, 0, 0, 1, 0, 0}
Y = {1, 1, 1, 0, 0, 0}

Here, the higher precision (ip2) ought to be 3 and the lower (ip)
ought to be 2.  The product check however makes the lower one as 0.  I
didn't find any input that actually triggered this bug, but here's a
patch to fix it anyway.  I had written it some time back, but it was
on another branch and had forgotten to update the submitted patch;
sorry about that.

Verified that it does not cause any regressions in the testsuite.  OK
to commit?

Siddhesh

	* sysdeps/ieee754/dbl-64/mpa.c (__mul): Fix determination of
	the lower precision input.

diff --git a/sysdeps/ieee754/dbl-64/mpa.c b/sysdeps/ieee754/dbl-64/mpa.c
index 7eba51e..a5aace7 100644
--- a/sysdeps/ieee754/dbl-64/mpa.c
+++ b/sysdeps/ieee754/dbl-64/mpa.c
@@ -614,6 +614,7 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
   int i, j, k, ip, ip2;
   double u, zk;
   double *diag;
+  const mp_no *a;
 
   /* Is z=0?  */
   if (__glibc_unlikely (X[0] * Y[0] == ZERO))
@@ -628,9 +629,11 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
     if (X[ip2] != ZERO || Y[ip2] != ZERO)
       break;
 
+  a = X[ip2] != ZERO ? y : x;
+
   /* ... and here, at least one of them is still zero.  */
   for (ip = ip2; ip > 0; ip--)
-    if (X[ip] * Y[ip] != ZERO)
+    if (a->d[ip] != ZERO)
       break;
 
   /* The product looks like this for p = 3 (as an example):


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]