summaryrefslogtreecommitdiff
path: root/libstd/bigint.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-12 00:30:15 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-12 00:30:15 -0400
commitbc3ef744e68cc21d9e899f177e934a937aec8afc (patch)
treecbed328b2505197ab6fa3c6402f80890e31e781d /libstd/bigint.myr
parent8f5b7baf54f08113a4b46aeafa795163e70f5ac5 (diff)
downloadmc-bc3ef744e68cc21d9e899f177e934a937aec8afc.tar.gz
Make bigfmt match the fmt functions.
Diffstat (limited to 'libstd/bigint.myr')
-rw-r--r--libstd/bigint.myr27
1 files changed, 20 insertions, 7 deletions
diff --git a/libstd/bigint.myr b/libstd/bigint.myr
index baf961b..00feac9 100644
--- a/libstd/bigint.myr
+++ b/libstd/bigint.myr
@@ -25,7 +25,11 @@ pkg std =
const bigdup : (a : bigint# -> bigint#)
const bigassign : (d : bigint#, s : bigint# -> bigint#)
const bigparse : (s : byte[:] -> option(bigint#))
- const bigfmt : (b : byte[:], a : bigint# -> size)
+ const bigbfmt : (b : byte[:], a : bigint# -> size)
+ const bigfmt : (a : bigint# -> byte[:])
+ /*
+ const bigtoint : (a : bigint# -> @a::(numeric,integral))
+ */
/* some useful predicates */
const bigiszero : (a : bigint# -> bool)
@@ -40,6 +44,9 @@ pkg std =
const bigdivmod : (a : bigint#, b : bigint# -> (bigint#, bigint#))
const bigshl : (a : bigint#, b : bigint# -> bigint#)
const bigshr : (a : bigint#, b : bigint# -> bigint#)
+ /*
+ const bigpow : (a : bigint#, b : bigint# -> bigint#)
+ */
/* bigint*int -> bigint ops */
const bigaddi : (a : bigint#, b : int64 -> bigint#)
@@ -48,6 +55,9 @@ pkg std =
const bigdivi : (a : bigint#, b : int64 -> bigint#)
const bigshli : (a : bigint#, b : uint64 -> bigint#)
const bigshri : (a : bigint#, b : uint64 -> bigint#)
+ /*
+ const bigpowi : (a : bigint#, b : uint64 -> bigint#)
+ */
;;
const Base = 0x100000000ul
@@ -88,9 +98,16 @@ const bigassign = {d, s
-> d
}
+const bigfmt = {a
+ var buf : byte[1024]
+ var n
+
+ n = bigbfmt(buf[:], a)
+ -> sldup(buf[:n])
+}
/* for now, just dump out something for debugging... */
-const bigfmt = {buf, val
+const bigbfmt = {buf, val
const digitchars = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
var v
var n, i
@@ -128,7 +145,7 @@ const bigfmt = {buf, val
}
const bigparse = {str
- var c, val, base
+ var c, val : uint32, base
var v, b
var a
@@ -315,10 +332,6 @@ const bigmul = {a, b
;;
w = slzalloc(a.dig.len + b.dig.len)
for j = 0; j < b.dig.len; j++
- if a.dig[j] == 0
- w[j] = 0
- continue
- ;;
carry = 0
for i = 0; i < a.dig.len; i++
ai = a.dig[i] castto(uint64)