shithub: mc

Download patch

ref: 4165e7ed3983d0a83df8c62932edbe514cbfdad0
parent: 170e5650b446699af330d2a1a6a8046cb78b9b3c
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 7 13:43:05 EST 2015

Add bigclear.

--- a/libstd/bigint.myr
+++ b/libstd/bigint.myr
@@ -25,8 +25,9 @@
 	const bigassign	: (d : bigint#, s : bigint# -> bigint#)
 	const bigmove	: (d : bigint#, s : bigint# -> bigint#)
 	const bigparse	: (s : byte[:] -> option(bigint#))
-	const bigbfmt	: (b : byte[:], a : bigint#, base : int -> size)
+	const bigclear	: (a : bigint# -> bigint#)
 	const bigfmt	: (a : bigint#, base : int -> byte[:])
+	const bigbfmt	: (b : byte[:], a : bigint#, base : int -> size)
 	/*
 	const bigtoint	: (a : bigint#	-> @a::(numeric,integral))
 	*/
@@ -108,6 +109,12 @@
 	-> d
 }
 
+const bigclear = {v
+	std.slfree(v.dig)
+	v.sign = 0
+	v.dig = [][:]
+	-> v
+}
 
 const bigfmt = {a, base
 	var buf
@@ -364,7 +371,7 @@
 		| `After: /* b is negative */
 		    -> usub(a, b)
 		| `Equal:
-			die("Impossible. Equal vals with different sign.")
+		    -> bigclear(a)
 		;;
 	;;
 	-> a