aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math/big
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/math/big')
-rw-r--r--lib/std/math/big/int.zig2
-rw-r--r--lib/std/math/big/int_test.zig22
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig
index b6d7731f1a..92b3f80429 100644
--- a/lib/std/math/big/int.zig
+++ b/lib/std/math/big/int.zig
@@ -99,7 +99,7 @@ pub const Mutable = struct {
pub fn toManaged(self: Mutable, allocator: *Allocator) Managed {
return .{
.allocator = allocator,
- .limbs = limbs,
+ .limbs = self.limbs,
.metadata = if (self.positive)
self.len & ~Managed.sign_bit
else
diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig
index d7e354879e..a86b55d2de 100644
--- a/lib/std/math/big/int_test.zig
+++ b/lib/std/math/big/int_test.zig
@@ -2,6 +2,7 @@ const std = @import("../../std.zig");
const mem = std.mem;
const testing = std.testing;
const Managed = std.math.big.int.Managed;
+const Mutable = std.math.big.int.Mutable;
const Limb = std.math.big.Limb;
const DoubleLimb = std.math.big.DoubleLimb;
const maxInt = std.math.maxInt;
@@ -1453,3 +1454,24 @@ test "big.int gcd one large" {
testing.expect((try r.to(u64)) == 1);
}
+
+test "big.int mutable to managed" {
+ const allocator = testing.allocator;
+ var limbs_buf = try allocator.alloc(Limb, 8);
+ defer allocator.free(limbs_buf);
+
+ var a = Mutable.init(limbs_buf, 0xdeadbeef);
+ var a_managed = a.toManaged(allocator);
+
+ testing.expect(a.toConst().eq(a_managed.toConst()));
+}
+
+test "big.int const to managed" {
+ var a = try Managed.initSet(testing.allocator, 123423453456);
+ defer a.deinit();
+
+ var b = try a.toConst().toManaged(testing.allocator);
+ defer b.deinit();
+
+ testing.expect(a.toConst().eq(b.toConst()));
+}