shithub: riscv

Download patch

ref: 15c6cd755557de5bb91c14668f9f0c2cbcbe988e
parent: 609a9922adac98516b33d67dc98b432ac9c10cc9
author: aiju <devnull@localhost>
date: Tue Dec 8 15:26:17 EST 2015

mp: strtomp support for bases 2,4,8

--- a/sys/src/libmp/port/strtomp.c
+++ b/sys/src/libmp/port/strtomp.c
@@ -44,14 +44,16 @@
 }
 
 static char*
-from16(char *a, mpint *b)
+frompow2(char *a, mpint *b, int s)
 {
 	char *p, *next;
 	int i;
 	mpdigit x;
+	int sn;
 
+	sn = 1<<s;
 	for(p = a; *p; p++)
-		if(tab.t16[*(uchar*)p] == INVAL)
+		if((uchar)tab.t16[*(uchar*)p] >= sn)
 			break;
 	mpbits(b, (p-a)*4);
 	b->top = 0;
@@ -58,7 +60,7 @@
 	next = p;
 	while(p > a){
 		x = 0;
-		for(i = 0; i < Dbits; i += 4){
+		for(i = 0; i < Dbits; i += s){
 			if(p <= a)
 				break;
 			x |= tab.t16[*(uchar*)--p]<<i;
@@ -178,12 +180,21 @@
 	}
 
 	switch(base){
+	case 2:
+		e = frompow2(a, b, 1);
+		break;
+	case 4:
+		e = frompow2(a, b, 2);
+		break;
+	case 8:
+		e = frompow2(a, b, 3);
+		break;
 	case 10:
 		e = from10(a, b);
 		break;
 	default:
 	case 16:
-		e = from16(a, b);
+		e = frompow2(a, b, 4);
 		break;
 	case 32:
 		e = from32(a, b);