about summary refs log tree commit diff
path: root/src/math/remquo.c
diff options
context:
space:
mode:
authornsz <nsz@port70.net>2012-05-08 00:22:56 +0200
committernsz <nsz@port70.net>2012-05-08 00:22:56 +0200
commit3738a96e052603403e085e9a1024289ba3e09188 (patch)
treefb183fb5fc9f79797bd38f87aa7f51261ef9da44 /src/math/remquo.c
parent0e195dfaa4902a73179f7ab296d47f01d3518ad3 (diff)
downloadmusl-3738a96e052603403e085e9a1024289ba3e09188.tar.gz
musl-3738a96e052603403e085e9a1024289ba3e09188.tar.xz
musl-3738a96e052603403e085e9a1024289ba3e09188.zip
math: fix remquo.c when x==-y and a subnormal remainder bug as well
backported fix from freebsd:
http://svnweb.FreeBSD.org/base?view=revision&revision=233973
Diffstat (limited to 'src/math/remquo.c')
-rw-r--r--src/math/remquo.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/math/remquo.c b/src/math/remquo.c
index e92984ed..085466e6 100644
--- a/src/math/remquo.c
+++ b/src/math/remquo.c
@@ -44,7 +44,7 @@ double remquo(double x, double y, int *quo)
 			goto fixup;
 		}
 		if (lx == ly) {            /* |x| = |y| return x*0 */
-			*quo = 1;
+			*quo = sxy ? -1 : 1;
 			return Zero[(uint32_t)sx>>31];
 		}
 	}
@@ -127,6 +127,7 @@ double 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[(uint32_t)sx>>31];
 	}
@@ -144,10 +145,10 @@ double remquo(double x, double y, int *quo)
 			hx >>= n;
 		} else if (n <= 31) {
 			lx = (hx<<(32-n))|(lx>>n);
-			hx = sx;
+			hx = 0;
 		} else {
 			lx = hx>>(n-32);
-			hx = sx;
+			hx = 0;
 		}
 	}
 fixup: