shithub: riscv

Download patch

ref: 43bb71c8cca061a705689be27906207329c3b5f7
parent: 344ff48512561b57022c1f686005b3283da07cc5
author: aiju <devnull@localhost>
date: Sun Aug 28 08:00:25 EDT 2016

mpdiv: negative divisor has to flip sign of quotient

--- a/sys/src/libmp/port/mpdiv.c
+++ b/sys/src/libmp/port/mpdiv.c
@@ -24,9 +24,12 @@
 	if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){
 		vlong r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1);
 		if(quotient != nil){
+			sign = divisor->sign;
 			for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++)
 				;
 			mpright(dividend, s, quotient);
+			if(sign < 0 && quotient->top != 0)
+				quotient->sign ^= -2;
 		}
 		if(remainder != nil){
 			remainder->flags |= dividend->flags & MPtimesafe;