shithub: riscv

Download patch

ref: a7a07b2d43529b60a239bbb2c7acabcbdbb812e5
parent: 0930daf295aaeca0e58e1cb73a60b78c85749fe9
author: aiju <devnull@localhost>
date: Sat May 5 08:03:45 EDT 2018

mpdiv: get signs right...

--- a/sys/src/libmp/port/mpdiv.c
+++ b/sys/src/libmp/port/mpdiv.c
@@ -52,10 +52,6 @@
 	
 	qsign = divisor->sign * dividend->sign;
 	rsign = dividend->sign;
-	if(quotient != nil)
-		quotient->sign = qsign;
-	if(remainder != nil)
-		remainder->sign = rsign;
 
 	// D1: shift until divisor, v, has hi bit set (needed to make trial
 	//     divisor accurate)
@@ -128,11 +124,15 @@
 	if(qp != nil){
 		assert((quotient->flags & MPtimesafe) == 0);
 		mpnorm(quotient);
+		if(quotient->top != 0)
+			quotient->sign = qsign;
 	}
 
 	if(remainder != nil){
 		assert((remainder->flags & MPtimesafe) == 0);
 		mpright(u, s, remainder);	// u is the remainder shifted
+		if(remainder->top != 0)
+			remainder->sign = rsign;
 	}
 
 	mpfree(t);