summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-02-05 00:21:59 -0800
committerOri Bernstein <ori@eigenstate.org>2015-02-05 00:21:59 -0800
commit38a875c05a009fdd298e7a93086654c8b78b2f63 (patch)
tree30b3b15a9d43d545fda82bb098d28083ea7e2206 /test
parent961b64f18bcd6f6280a79638fd0634ff915cc4aa (diff)
downloadmc-38a875c05a009fdd298e7a93086654c8b78b2f63.tar.gz
Add more stdbigint test cases.
Diffstat (limited to 'test')
-rw-r--r--test/data/stdbigint-expected5
-rw-r--r--test/stdbigint.myr62
2 files changed, 56 insertions, 11 deletions
diff --git a/test/data/stdbigint-expected b/test/data/stdbigint-expected
index 5c2b140..9eb549e 100644
--- a/test/data/stdbigint-expected
+++ b/test/data/stdbigint-expected
@@ -1,4 +1,9 @@
517347321949036993306
+0 == 0
1234567812346789666677778888 / 123456781234678966667777 == 10000
1208908684563961789813300 / 263951815549716 == 4580035496
5192296858534810493479828944327220 / 75557863709417659441940 == 68719476751
+75557863709417659441940 / 5192296858534810493479828944327220 == 0
+5192296858534810493479828944327220 % 75557863709417659441940 == 257025710597479990280
+(1 ^ 3) % 2 == 1
+(5192296858534810493479828944327220 ^ 75557863709417659441940) % 755578 == 49054
diff --git a/test/stdbigint.myr b/test/stdbigint.myr
index 45db0e8..ae465af 100644
--- a/test/stdbigint.myr
+++ b/test/stdbigint.myr
@@ -15,8 +15,9 @@ type cmd = union
const main = {
var a, b, c, d, e
- var buf : byte[4096], n
+ var buf : byte[64], n
+ /* a few combined ops */
a = std.mkbigint(1234)
b = std.mkbigint(0x7fffffff)
c = std.mkbigint(7919)
@@ -37,6 +38,8 @@ const main = {
n = std.bigbfmt(buf[:], a, 0)
std.put("%s\n", buf[:n])
+ /* make sure we format '0' correctly */
+ run(std.mk(`Res (std.mk(`Val "0"))))
/* smoke test for division */
run(std.mk(`Res \
std.mk(`Div (\
@@ -50,11 +53,42 @@ const main = {
std.mk(`Div (\
std.mk(`Val "5192296858534810493479828944327220"), \
std.mk(`Val "75557863709417659441940")))))
+ run(std.mk(`Res \
+ std.mk(`Div (\
+ std.mk(`Val "75557863709417659441940"), \
+ std.mk(`Val "5192296858534810493479828944327220")))))
+
+ /* smoke test for mod */
+ run(std.mk(`Res \
+ std.mk(`Mod (\
+ std.mk(`Val "5192296858534810493479828944327220"), \
+ std.mk(`Val "75557863709417659441940")))))
+
+ run(std.mk(`Res \
+ std.mk(`Modpow (\
+ std.mk(`Val "1"), \
+ std.mk(`Val "3"), \
+ std.mk(`Val "2")))))
+
+ run(std.mk(`Res \
+ std.mk(`Modpow (\
+ std.mk(`Val "5192296858534810493479828944327220"), \
+ std.mk(`Val "75557863709417659441940"), \
+ std.mk(`Val "755578")))))
+ /* BOTCHED
+ run(std.mk(`Res \
+ std.mk(`Modpow (\
+ std.mk(`Val "5192296858534810493479828944327220"), \
+ std.mk(`Val "755578"), \
+ std.mk(`Val "75557863709417659441940")))))
+ */
+
}
const run = {e : cmd#
- var buf : byte[4096]
- var v, n
+ var buf : byte[2048]
+ var a, b, c /* scratch vars */
+ var n /* buf len */
match e#
| `Add (x, y): -> binop("+", std.bigadd, x, y)
@@ -65,17 +99,23 @@ const run = {e : cmd#
| `Shl (x, y): -> binop("<<", std.bigshl, x, y)
| `Shr (x, y): -> binop(">>", std.bigshr, x, y)
| `Val x:
- v = try(std.bigparse(x))
- n = std.bigbfmt(buf[:], v, 0)
+ a = try(std.bigparse(x))
+ n = std.bigbfmt(buf[:], a, 0)
std.put("%s", buf[:n])
- -> v
+ -> a
| `Res r:
- v = run(r)
- n = std.bigbfmt(buf[:], v, 0)
+ a = run(r)
+ n = std.bigbfmt(buf[:], a, 0)
std.put(" == %s\n", buf[:n])
- | `Modpow (x, y, m):
- n = std.bigbfmt(buf[:], std.bigmodpow(run(x), run(y), run(m)), 0)
- std.put("(%s ^ %s) % %s = %s\n", x, y, m, buf[:n])
+ -> a
+ | `Modpow (x, y, z):
+ std.put("(");
+ a = run(x)
+ std.put(" ^ ")
+ b = run(y)
+ std.put(") %% ")
+ c = run(z)
+ -> std.bigmodpow(a, b, c)
;;
}