diff options
| author | Jimmi Holst Christensen <jhc@dismail.de> | 2022-01-07 18:57:39 +0100 |
|---|---|---|
| committer | Jimmi Holst Christensen <jhc@dismail.de> | 2022-01-07 19:50:00 +0100 |
| commit | a68e6cd3d73680282d06e2d7676f0bca3056c71b (patch) | |
| tree | 94e636092225e1b7cc60a1593501cf907a7ba696 /src/value.zig | |
| parent | c08b190c6918b33d27ceffe1ab3afd5d7f6370ea (diff) | |
| download | zig-a68e6cd3d73680282d06e2d7676f0bca3056c71b.tar.gz zig-a68e6cd3d73680282d06e2d7676f0bca3056c71b.zip | |
Return Value.zero when the result of shr requires zero bits
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 10 |
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, |
