Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] Allow bigparse to handle negative numbers


---
 lib/std/bigint.myr | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr
index cbabe0fa..c13f0df9 100644
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -234,6 +234,12 @@ const bigparse = {str
 	var val : int, base
 	var v, b
 	var a
+	var s = 1
+
+	if hasprefix(str, "-")
+		s = -1
+		str = str[1:]
+	;;
 
 	if hasprefix(str, "0x") || hasprefix(str, "0X")
 		base = 16
@@ -271,7 +277,7 @@ const bigparse = {str
 		if val == 0
 			v.sign = 0
 		else
-			v.sign = 1
+			v.sign = s
 		;;
 		bigmul(a, b)
 		bigadd(a, v)
-- 
2.20.1


References:
[PATCH 0/3] Handle negatives in bigint arithmetic"S. Gilles" <sgilles@xxxxxxxxxxxx>