summaryrefslogtreecommitdiff
path: root/lib/std/bigint.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/bigint.myr')
-rw-r--r--lib/std/bigint.myr14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr
index 45170dd..129890c 100644
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -28,6 +28,7 @@ pkg std =
const bigdup : (a : bigint# -> bigint#)
const bigassign : (d : bigint#, s : bigint# -> bigint#)
const bigmove : (d : bigint#, s : bigint# -> bigint#)
+ const bigsteal : (d : bigint#, s : bigint# -> bigint#)
const bigparse : (s : byte[:] -> option(bigint#))
const bigclear : (a : bigint# -> bigint#)
const bigbfmt : (b : byte[:], a : bigint#, base : int -> size)
@@ -162,6 +163,12 @@ const bigmove = {d, s
-> d
}
+const bigsteal = {d, s
+ bigmove(d, s);
+ bigfree(s)
+ -> d
+}
+
const bigclear = {v
std.slfree(v.dig)
v.sign = 0
@@ -547,7 +554,7 @@ const bigdiv = {a : bigint#, b : bigint# -> bigint#
(q, r) = bigdivmod(a, b)
bigfree(r)
- -> bigmove(a, q)
+ -> bigsteal(a, q)
}
const bigmod = {a : bigint#, b : bigint# -> bigint#
@@ -555,7 +562,7 @@ const bigmod = {a : bigint#, b : bigint# -> bigint#
(q, r) = bigdivmod(a, b)
bigfree(q)
- -> bigmove(a, r)
+ -> bigsteal(a, r)
}
/* a /= b */
@@ -665,6 +672,7 @@ const bigdivmod = {a : bigint#, b : bigint# -> (bigint#, bigint#)
/* undo the biasing for remainder */
bigshri(u, shift)
trim(q)
+ bigfree(v)
-> (trim(q), trim(u))
}
@@ -698,7 +706,7 @@ const bigmodpow = {base, exp, mod
bigmul(base, base)
bigmod(base, mod)
;;
- -> bigmove(base, r)
+ -> bigsteal(base, r)
}
/* returns the number of leading zeros */