diff options
author | Ori Bernstein <ori@eigenstate.org> | 2014-09-06 21:18:34 -0400 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2014-09-06 21:18:34 -0400 |
commit | d0331c3cfb6f27afe416b9cdb7b15e18b9083e3e (patch) | |
tree | 4da43f1083896366ddf65288276a7703f4c5d1fa | |
parent | ebdd2476cc2b5f0dea539efeae5151ada62c1ec6 (diff) | |
download | mc-d0331c3cfb6f27afe416b9cdb7b15e18b9083e3e.tar.gz |
Fix missing methods.
-rw-r--r-- | libstd/bigint.myr | 52 | ||||
-rw-r--r-- | libstd/bitset.myr | 2 |
2 files changed, 50 insertions, 4 deletions
diff --git a/libstd/bigint.myr b/libstd/bigint.myr index 813e4ce..1b41056 100644 --- a/libstd/bigint.myr +++ b/libstd/bigint.myr @@ -20,7 +20,7 @@ pkg std = ;; /* administrivia */ - const mkbigint : (v : int32 -> bigint#) + generic mkbigint : (v : @a::(numeric,integral) -> bigint#) const bigfree : (a : bigint# -> void) const bigdup : (a : bigint# -> bigint#) const bigassign : (d : bigint#, s : bigint# -> bigint#) @@ -52,8 +52,10 @@ pkg std = const Base = 0x100000000ul -const mkbigint = {v +generic mkbigint = {v : @a::(integral,numeric) var a + var i + a = zalloc() a.dig = slalloc(1) @@ -63,7 +65,11 @@ const mkbigint = {v elif v > 0 a.sign = 1 ;; - a.dig[0] = (v castto(uint32)) + i = 0 + while v != 0 + a.dig[i++] = (v castto(uint32)) + v /= (Base castto(@a::(numeric,integral))) + ;; -> trim(a) } @@ -501,6 +507,46 @@ const bigshr = {a, b ;; } +/* a + b, b is integer. +FIXME: acually make this a performace improvement +*/ +const bigaddi = {a, b + var bigb + + bigb = mkbigint(b) + bigadd(a, bigb) + bigfree(bigb) + -> a +} + +const bigsubi = {a, b + var bigb + + bigb = mkbigint(b) + bigsub(a, bigb) + bigfree(bigb) + -> a +} + +const bigmuli = {a, b + var bigb + + bigb = mkbigint(b) + bigmul(a, bigb) + bigfree(bigb) + -> a +} + +const bigdivi = {a, b + var bigb + + bigb = mkbigint(b) + bigdiv(a, bigb) + bigfree(bigb) + -> a +} + + /* a << s, with integer arg. logical left shift. any other type would be illogical. diff --git a/libstd/bitset.myr b/libstd/bitset.myr index 1d3b924..0cf8bbf 100644 --- a/libstd/bitset.myr +++ b/libstd/bitset.myr @@ -21,7 +21,7 @@ pkg std = const bsintersect : (a : bitset#, b : bitset# -> void) const bsunion : (a : bitset#, b : bitset# -> void) const bseq : (a : bitset#, b : bitset# -> bool) - const bsissub : (a : bitset#, b : bitset# -> bool) + const bsissubset : (a : bitset#, b : bitset# -> bool) const bsclear : (bs : bitset# -> bitset#) ;; |