summaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2019-02-19 08:19:08 -0500
committerOri Bernstein <ori@markovcorp.com>2019-02-19 13:26:17 -0800
commit36f4100dcea54700c0441a4667f601bcb5b1c59e (patch)
tree6c0c9a5f56da5b38b8c6679dc79f81116e7f56b6 /lib/std
parentc95732cc7a4f47740ace668693d4216d9482da1a (diff)
downloadmc-36f4100dcea54700c0441a4667f601bcb5b1c59e.tar.gz
Allow bigparse to handle negative numbers
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/bigint.myr8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr
index cbabe0f..c13f0df 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)