| ... | @@ -2635,9 +2635,17 @@ pub const Value = extern union { | ... | @@ -2635,9 +2635,17 @@ pub const Value = extern union { |
| 2635 | var lhs_space: Value.BigIntSpace = undefined; | 2635 | var lhs_space: Value.BigIntSpace = undefined; |
| 2636 | const lhs_bigint = lhs.toBigInt(&lhs_space); | 2636 | const lhs_bigint = lhs.toBigInt(&lhs_space); |
| 2637 | const shift = @intCast(usize, rhs.toUnsignedInt()); | 2637 | 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 | |
| 2638 | const limbs = try allocator.alloc( | 2646 | const limbs = try allocator.alloc( |
| 2639 | std.math.big.Limb, | 2647 | std.math.big.Limb, |
| 2640 | lhs_bigint.limbs.len - (shift / (@sizeOf(std.math.big.Limb) * 8)), | 2648 | result_limbs, |
| 2641 | ); | 2649 | ); |
| 2642 | var result_bigint = BigIntMutable{ | 2650 | var result_bigint = BigIntMutable{ |
| 2643 | .limbs = limbs, | 2651 | .limbs = limbs, |