shithub: riscv

Download patch

ref: 1f9bdb6f5d9699493f6bce572cbbb58ef3b4ad27
parent: bdc87e17bd2522552f3c97c741bda0ae29df3528
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Aug 28 12:46:32 EDT 2016

libmp: mpdiv(): fix divisor==quotient case (again)

--- a/sys/src/libmp/port/mpdiv.c
+++ b/sys/src/libmp/port/mpdiv.c
@@ -24,10 +24,11 @@
 	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(divisor->sign < 0)
+			if(sign < 0)
 				quotient->sign ^= (-mpmagcmp(quotient, mpzero) >> 31) << 1;
 		}
 		if(remainder != nil){