diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2023-01-03 02:03:54 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2023-01-03 02:03:54 -0500 |
commit | c94edbe007910755087e71cbb1a6a349d75e9b85 (patch) | |
tree | f466d26643f7caeb9a1f9a8fc5365338bc8637e8 /tnslc/util.tnsl | |
parent | 17c838e4755fefadfb001c19ba2f079eaba340f6 (diff) |
Basic addition and subtraction
Diffstat (limited to 'tnslc/util.tnsl')
-rw-r--r-- | tnslc/util.tnsl | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tnslc/util.tnsl b/tnslc/util.tnsl index 156cbb4..d4a7b4b 100644 --- a/tnslc/util.tnsl +++ b/tnslc/util.tnsl @@ -69,9 +69,10 @@ /; string_from_int(int i) [{}uint8] ;{}uint8 c = "" + ;bool n = false /; if (i < 0) - ;c = "-" + ;n = true ;i = -i ;/ @@ -82,17 +83,28 @@ ;c.append(digit_to_char(i)) ;/ + /;if (n) + ;c.append('-') + ;/ + ;return reverse_string(c) ;/ /; int_from_string ({}uint8 str) [int] ;bool inv = str{0} == '-' ;int out = 0 + ;int fac = 10 + ;int i = 0 - /; loop () - + /; if (inv) + ;i++ + ;/ + + /; loop (i < len str) [i++] + ;out = out * fac + ;out = out + str{i} - '0' ;/ - + /; if (inv) ;out = -out ;/ |