authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2022-01-07 18:57:39+01:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2022-01-07 19:50:00+01:00
loga68e6cd3d73680282d06e2d7676f0bca3056c71b
tree94e636092225e1b7cc60a1593501cf907a7ba696
parentc08b190c6918b33d27ceffe1ab3afd5d7f6370ea

Return Value.zero when the result of shr requires zero bits


1 files changed, 9 insertions(+), 1 deletions(-)

src/value.zig+9-1
......@@ -2635,9 +2635,17 @@ pub const Value = extern union {
26352635 var lhs_space: Value.BigIntSpace = undefined;
26362636 const lhs_bigint = lhs.toBigInt(&lhs_space);
26372637 const shift = @intCast(usize, rhs.toUnsignedInt());
2638
2639 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
2640 if (result_limbs == 0) {
2641 // The shift is enough to remove all the bits from the number, which means the
2642 // result is zero.
2643 return Value.zero;
2644 }
2645
26382646 const limbs = try allocator.alloc(
26392647 std.math.big.Limb,
2640 lhs_bigint.limbs.len - (shift / (@sizeOf(std.math.big.Limb) * 8)),
2648 result_limbs,
26412649 );
26422650 var result_bigint = BigIntMutable{
26432651 .limbs = limbs,