summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2012-04-07 03:59:12 +0000
committerdas <das@FreeBSD.org>2012-04-07 03:59:12 +0000
commit5d2625f37f906b2187ea184cba9c2cc28f46d988 (patch)
treee8eaea781c54d66892fb03412a3054c69976c30c /lib
parent89f805c29a4e922e5a7d624cd548006901e33ee7 (diff)
downloadFreeBSD-src-5d2625f37f906b2187ea184cba9c2cc28f46d988.zip
FreeBSD-src-5d2625f37f906b2187ea184cba9c2cc28f46d988.tar.gz
Fix a bug in remquo{,f,l}, in which the quotient didn't always have the
correct sign when the remainder was 0. Fix a separate bug in remquo alone, in which the remainder and quotient were both off by a bit in certain cases involving subnormal remainders. The bugs affected all platforms except amd64 and i386, on which the routines are implemented in assembly. PR: 166463 Submitted by: Ilya Burylov MFC after: 2 weeks
Diffstat (limited to 'lib')
-rw-r--r--lib/msun/src/s_remquo.c7
-rw-r--r--lib/msun/src/s_remquof.c3
-rw-r--r--lib/msun/src/s_remquol.c3
3 files changed, 8 insertions, 5 deletions
diff --git a/lib/msun/src/s_remquo.c b/lib/msun/src/s_remquo.c
index a64277a..d811c69 100644
--- a/lib/msun/src/s_remquo.c
+++ b/lib/msun/src/s_remquo.c
@@ -51,7 +51,7 @@ remquo(double x, double y, int *quo)
goto fixup; /* |x|<|y| return x or x-y */
}
if(lx==ly) {
- *quo = 1;
+ *quo = (sxy ? -1 : 1);
return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
}
}
@@ -114,6 +114,7 @@ remquo(double x, double y, int *quo)
/* convert back to floating value and restore the sign */
if((hx|lx)==0) { /* return sign(x)*0 */
+ q &= 0x7fffffff;
*quo = (sxy ? -q : q);
return Zero[(u_int32_t)sx>>31];
}
@@ -129,9 +130,9 @@ remquo(double x, double y, int *quo)
lx = (lx>>n)|((u_int32_t)hx<<(32-n));
hx >>= n;
} else if (n<=31) {
- lx = (hx<<(32-n))|(lx>>n); hx = sx;
+ lx = (hx<<(32-n))|(lx>>n); hx = 0;
} else {
- lx = hx>>(n-32); hx = sx;
+ lx = hx>>(n-32); hx = 0;
}
}
fixup:
diff --git a/lib/msun/src/s_remquof.c b/lib/msun/src/s_remquof.c
index 3141642..f7b4c00 100644
--- a/lib/msun/src/s_remquof.c
+++ b/lib/msun/src/s_remquof.c
@@ -46,7 +46,7 @@ remquof(float x, float y, int *quo)
q = 0;
goto fixup; /* |x|<|y| return x or x-y */
} else if(hx==hy) {
- *quo = 1;
+ *quo = (sxy ? -1 : 1);
return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
}
@@ -88,6 +88,7 @@ remquof(float x, float y, int *quo)
/* convert back to floating value and restore the sign */
if(hx==0) { /* return sign(x)*0 */
+ q &= 0x7fffffff;
*quo = (sxy ? -q : q);
return Zero[(u_int32_t)sx>>31];
}
diff --git a/lib/msun/src/s_remquol.c b/lib/msun/src/s_remquol.c
index 9f5b578..712651c 100644
--- a/lib/msun/src/s_remquol.c
+++ b/lib/msun/src/s_remquol.c
@@ -96,7 +96,7 @@ remquol(long double x, long double y, int *quo)
goto fixup; /* |x|<|y| return x or x-y */
}
if(ux.bits.manh==uy.bits.manh && ux.bits.manl==uy.bits.manl) {
- *quo = 1;
+ *quo = (sxy ? -1 : 1);
return Zero[sx]; /* |x|=|y| return x*0*/
}
}
@@ -138,6 +138,7 @@ remquol(long double x, long double y, int *quo)
/* convert back to floating value and restore the sign */
if((hx|lx)==0) { /* return sign(x)*0 */
+ q &= 0x7fffffff;
*quo = (sxy ? -q : q);
return Zero[sx];
}
OpenPOWER on IntegriCloud