summaryrefslogtreecommitdiff
path: root/test/stdbigint.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-14 03:21:03 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-14 03:21:03 -0400
commit8f2b7470799a4851a5f73e8566b18823c7fe72df (patch)
treecb1051272da3f32e0b206598705c1ddefd7b55ad /test/stdbigint.myr
parent4a59ae120acc8cbb8ee2bccbd0bcbd171f8db7b5 (diff)
downloadmc-8f2b7470799a4851a5f73e8566b18823c7fe72df.tar.gz
Fix bigint parsing for hex.
We weren't trimming the '0x' hex prefix,and that confused our code when it got the 'x' and tried to treat it as a digit.
Diffstat (limited to 'test/stdbigint.myr')
-rw-r--r--test/stdbigint.myr88
1 files changed, 88 insertions, 0 deletions
diff --git a/test/stdbigint.myr b/test/stdbigint.myr
new file mode 100644
index 0000000..a0afec6
--- /dev/null
+++ b/test/stdbigint.myr
@@ -0,0 +1,88 @@
+use std
+
+const main = {
+ var a, b, c, d, e
+ var buf : byte[4096], n
+
+ a = std.mkbigint(1234)
+ b = std.mkbigint(0x7fffffff)
+ c = std.mkbigint(7919)
+ d = std.mkbigint(113051)
+ e = std.mkbigint(11)
+
+ std.bigmul(a, b)
+ std.bigmul(a, b)
+ std.bigadd(a, c)
+ std.bigsub(a, d)
+ std.bigdiv(a, e)
+
+ std.bigfree(b)
+ std.bigfree(c)
+ std.bigfree(d)
+ std.bigfree(e)
+
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("%s\n", buf[:n])
+
+ /* smoke test */
+ match std.bigparse("1234_5678_1234_6789_6666_7777_8888")
+ | `std.Some val: a = val
+ | `std.None: std.die("Failed to parse a\n")
+ ;;
+ match std.bigparse("1234_5678_1234_6789_6666_7777")
+ | `std.Some val: b = val
+ | `std.None: std.die("Failed to parse b\n")
+ ;;
+
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("%s / ", buf[:n])
+ n = std.bigbfmt(buf[:], b, 0)
+ std.put("%s == ", buf[:n])
+
+ std.bigdiv(a, b)
+
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("%s\n", buf[:n])
+
+ match std.bigparse("0xffff_1234_1234_1234_1234")
+ | `std.Some val: a = val
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("a = %s \n", buf[:n])
+ | `std.None: std.die("Failed to parse a\n")
+ ;;
+ match std.bigparse("0xf010_1234_2314")
+ | `std.Some val: b = val
+ | `std.None: std.die("Failed to parse b\n")
+ ;;
+
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("%s / ", buf[:n])
+ n = std.bigbfmt(buf[:], b, 0)
+ std.put("%s == ", buf[:n])
+
+ std.bigdiv(a, b)
+
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("%s\n", buf[:n])
+
+ match std.bigparse("5192296858534810493479828944327220")
+ | `std.Some val: a = val
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("a = %s \n", buf[:n])
+ | `std.None: std.die("Failed to parse a\n")
+ ;;
+ match std.bigparse("75557863709417659441940")
+ | `std.Some val: b = val
+ | `std.None: std.die("Failed to parse b\n")
+ ;;
+
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("%s / ", buf[:n])
+ n = std.bigbfmt(buf[:], b, 0)
+ std.put("%s == ", buf[:n])
+
+ std.bigdiv(a, b)
+
+ n = std.bigbfmt(buf[:], a, 0)
+ std.put("%s\n", buf[:n])
+}