shithub: mc

Download patch

ref: bc3ef744e68cc21d9e899f177e934a937aec8afc
parent: 8f5b7baf54f08113a4b46aeafa795163e70f5ac5
author: Ori Bernstein <[email protected]>
date: Thu Sep 11 20:30:15 EDT 2014

Make bigfmt match the fmt functions.

--- a/libstd/bigint.myr
+++ b/libstd/bigint.myr
@@ -25,7 +25,11 @@
 	const bigdup	: (a : bigint# -> bigint#)
 	const bigassign	: (d : bigint#, s : bigint# -> bigint#)
 	const bigparse	: (s : byte[:] -> option(bigint#))
-	const bigfmt	: (b : byte[:], a : bigint# -> size)
+	const bigbfmt	: (b : byte[:], a : bigint# -> size)
+	const bigfmt	: (a : bigint# -> byte[:])
+	/*
+	const bigtoint	: (a : bigint#	-> @a::(numeric,integral))
+	*/
 
 	/* some useful predicates */
 	const bigiszero	: (a : bigint# -> bool)
@@ -40,6 +44,9 @@
 	const bigdivmod	: (a : bigint#, b : bigint# -> (bigint#, bigint#))
 	const bigshl	: (a : bigint#, b : bigint# -> bigint#)
 	const bigshr	: (a : bigint#, b : bigint# -> bigint#)
+	/*
+	const bigpow	: (a : bigint#, b : bigint# -> bigint#)
+	*/
 
 	/* bigint*int -> bigint ops */
 	const bigaddi	: (a : bigint#, b : int64 -> bigint#)
@@ -48,6 +55,9 @@
 	const bigdivi	: (a : bigint#, b : int64 -> bigint#)
 	const bigshli	: (a : bigint#, b : uint64 -> bigint#)
 	const bigshri	: (a : bigint#, b : uint64 -> bigint#)
+	/*
+	const bigpowi	: (a : bigint#, b : uint64 -> bigint#)
+	*/
 ;;
 
 const Base = 0x100000000ul
@@ -88,9 +98,16 @@
 	-> d
 }
 
+const bigfmt = {a
+	var buf : byte[1024]
+	var n
 
+	n = bigbfmt(buf[:], a)
+	-> sldup(buf[:n])
+}
+
 /* for now, just dump out something for debugging... */
-const bigfmt = {buf, val
+const bigbfmt = {buf, val
 	const digitchars = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
 	var v
 	var n, i
@@ -128,7 +145,7 @@
 }
 
 const bigparse = {str
-	var c, val, base
+	var c, val : uint32, base
 	var v, b
 	var a
 
@@ -315,10 +332,6 @@
 	;;
 	w  = slzalloc(a.dig.len + b.dig.len)
 	for j = 0; j < b.dig.len; j++
-		if a.dig[j] == 0
-			w[j] = 0
-			continue
-		;;
 		carry = 0
 		for i = 0; i < a.dig.len; i++
 			ai = a.dig[i] castto(uint64)
--- a/test/bigint.myr
+++ b/test/bigint.myr
@@ -21,7 +21,7 @@
 	std.bigfree(d)
 	std.bigfree(e)
 
-	n = std.bigfmt(buf[:], a)
+	n = std.bigbfmt(buf[:], a)
 	std.put("%s\n", buf[:n])
 
 	/* smoke test */
@@ -34,14 +34,14 @@
 	| `std.None: std.die("Failed to parse b\n")
 	;;
 
-	n = std.bigfmt(buf[:], a)
+	n = std.bigbfmt(buf[:], a)
 	std.put("%s / ", buf[:n])
-	n = std.bigfmt(buf[:], b)
+	n = std.bigbfmt(buf[:], b)
 	std.put("%s == ", buf[:n])
 
 	std.bigdiv(a, b)
 
-	n = std.bigfmt(buf[:], a)
+	n = std.bigbfmt(buf[:], a)
 	std.put("%s\n", buf[:n])
 
 	/* no shifting */
@@ -54,14 +54,14 @@
 	| `std.None: std.die("Failed to parse b\n")
 	;;
 
-	n = std.bigfmt(buf[:], a)
+	n = std.bigbfmt(buf[:], a)
 	std.put("%s / ", buf[:n])
-	n = std.bigfmt(buf[:], b)
+	n = std.bigbfmt(buf[:], b)
 	std.put("%s == ", buf[:n])
 
 	std.bigdiv(a, b)
 
-	n = std.bigfmt(buf[:], a)
+	n = std.bigbfmt(buf[:], a)
 	std.put("%s\n", buf[:n])
 
 	/* no shifting */
@@ -74,13 +74,13 @@
 	| `std.None: std.die("Failed to parse b\n")
 	;;
 
-	n = std.bigfmt(buf[:], a)
+	n = std.bigbfmt(buf[:], a)
 	std.put("%s / ", buf[:n])
-	n = std.bigfmt(buf[:], b)
+	n = std.bigbfmt(buf[:], b)
 	std.put("%s == ", buf[:n])
 
 	std.bigdiv(a, b)
 
-	n = std.bigfmt(buf[:], a)
+	n = std.bigbfmt(buf[:], a)
 	std.put("%s\n", buf[:n])
 }