Commit 616355807f
Changed files (2)
lib
std
math
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
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()));
+}