aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-08 01:00:59 -0500
committerGitHub <noreply@github.com>2022-01-08 01:00:59 -0500
commitc4ab8d9e12afbe07fc5b3cc4535a9fa2cfcad94d (patch)
tree87b00360b19a327864f09cfe12289650eb50650d /src/value.zig
parent1cdc51ec1012bc2a6d1c115eaaeb24a2a93c26c5 (diff)
parent3871d5e55a6d52bacadd80163540a171e014605f (diff)
downloadzig-c4ab8d9e12afbe07fc5b3cc4535a9fa2cfcad94d.tar.gz
zig-c4ab8d9e12afbe07fc5b3cc4535a9fa2cfcad94d.zip
Merge pull request #10532 from Hejsil/stage2-bit-shifting-passing
Stage2 bit_shifting.zig passing
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/value.zig b/src/value.zig
index 9da9fa6307..c4d35ad006 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -2635,9 +2635,17 @@ pub const Value = extern union {
var lhs_space: Value.BigIntSpace = undefined;
const lhs_bigint = lhs.toBigInt(&lhs_space);
const shift = @intCast(usize, rhs.toUnsignedInt());
+
+ const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
+ if (result_limbs == 0) {
+ // The shift is enough to remove all the bits from the number, which means the
+ // result is zero.
+ return Value.zero;
+ }
+
const limbs = try allocator.alloc(
std.math.big.Limb,
- lhs_bigint.limbs.len - (shift / (@sizeOf(std.math.big.Limb) * 8)),
+ result_limbs,
);
var result_bigint = BigIntMutable{
.limbs = limbs,