diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-05-09 01:52:26 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-05-09 01:52:26 -0700 |
| commit | bcb534c295d5cc6fd63caa570cc08e6b148a507c (patch) | |
| tree | 0b17cb1e632d894f50f25e550d5113f232b0e877 /lib/std/math/big | |
| parent | d9b00ee4ba48717ff6b306a6f9419e7b604ac04b (diff) | |
| parent | 74f52954b9cb40d59d80b839b45bb859146731a7 (diff) | |
| download | zig-bcb534c295d5cc6fd63caa570cc08e6b148a507c.tar.gz zig-bcb534c295d5cc6fd63caa570cc08e6b148a507c.zip | |
Merge branch 'llvm18'
Upgrades the LLVM, Clang, and LLD dependencies to LLVM 18.x
Related to #16270
Diffstat (limited to 'lib/std/math/big')
| -rw-r--r-- | lib/std/math/big/int.zig | 4 | ||||
| -rw-r--r-- | lib/std/math/big/int_test.zig | 40 |
2 files changed, 21 insertions, 23 deletions
diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 93ad1ccbe2..0a5c3c6ca5 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -340,7 +340,7 @@ pub const Mutable = struct { } const req_limbs = calcTwosCompLimbCount(bit_count); - const bit = @as(Log2Limb, @truncate(bit_count - 1)); + const bit: Log2Limb = @truncate(bit_count - 1); const signmask = @as(Limb, 1) << bit; // 0b0..010..0 where 1 is the sign bit. const mask = (signmask << 1) -% 1; // 0b0..011..1 where the leftmost 1 is the sign bit. @@ -2186,7 +2186,7 @@ pub const Const = struct { return if (self.positive) @as(T, @intCast(r)) else error.NegativeIntoUnsigned; } else { if (self.positive) { - return @as(T, @intCast(r)); + return @intCast(r); } else { if (math.cast(T, r)) |ok| { return -ok; diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig index 624bdc0b83..f42d73689b 100644 --- a/lib/std/math/big/int_test.zig +++ b/lib/std/math/big/int_test.zig @@ -288,31 +288,29 @@ test "string set bad base error" { } test "twos complement limit set" { - const test_types = [_]type{ - u64, - i64, - u1, - i1, - u0, - i0, - u65, - i65, - }; + try testTwosComplementLimit(u64); + try testTwosComplementLimit(i64); + try testTwosComplementLimit(u1); + try testTwosComplementLimit(i1); + try testTwosComplementLimit(u0); + try testTwosComplementLimit(i0); + try testTwosComplementLimit(u65); + try testTwosComplementLimit(i65); +} - inline for (test_types) |T| { - const int_info = @typeInfo(T).Int; +fn testTwosComplementLimit(comptime T: type) !void { + const int_info = @typeInfo(T).Int; - var a = try Managed.init(testing.allocator); - defer a.deinit(); + var a = try Managed.init(testing.allocator); + defer a.deinit(); - try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits); - const max: T = maxInt(T); - try testing.expect(max == try a.to(T)); + try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits); + const max: T = maxInt(T); + try testing.expect(max == try a.to(T)); - try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits); - const min: T = minInt(T); - try testing.expect(min == try a.to(T)); - } + try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits); + const min: T = minInt(T); + try testing.expect(min == try a.to(T)); } test "string to" { |
