[PATCH 2/3] Allow bigparse to handle negative numbers
[Thread Prev] | [Thread Next]
- Subject: [PATCH 2/3] Allow bigparse to handle negative numbers
- From: "S. Gilles" <sgilles@xxxxxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Tue, 19 Feb 2019 08:19:08 -0500
- To: myrddin-dev@xxxxxxxxxxxxxx
- Cc: "S. Gilles" <sgilles@xxxxxxxxxxxx>
---
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
| [PATCH 0/3] Handle negatives in bigint arithmetic | "S. Gilles" <sgilles@xxxxxxxxxxxx> |
- Prev by Date: [PATCH 1/3] Convert bigint tests to use testr
- Next by Date: [PATCH 3/3] Handle (-1) + (1) and (-3) - (-2) with bigints
- Previous by thread: [PATCH 1/3] Convert bigint tests to use testr
- Next by thread: [PATCH 3/3] Handle (-1) + (1) and (-3) - (-2) with bigints
- Index(es):