ref: f892d705f7ea448c9d36c7d1f1f41ff26ce86ede
dir: /test/stdbigint.myr/
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.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.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]) }