authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-31 00:42:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:57-07:00
log26fac15f485e89dc7106256e1aa79184c1761efd
tree59f0c3a453e0789f989bf096fe6fe235a6865b14
parentd019229c2c3432c9053594eb140b255c3be9ebeb

math.big.int: fix ctz of zero


2 files changed, 4 insertions(+), 4 deletions(-)

lib/std/math/big/int.zig+2-2
......@@ -2512,7 +2512,7 @@ pub const Const = struct {
25122512 return total_limb_lz + bits - total_limb_bits;
25132513 }
25142514
2515 pub fn ctz(a: Const) Limb {
2515 pub fn ctz(a: Const, bits: Limb) Limb {
25162516 // Limbs are stored in little-endian order.
25172517 var result: Limb = 0;
25182518 for (a.limbs) |limb| {
......@@ -2520,7 +2520,7 @@ pub const Const = struct {
25202520 result += limb_tz;
25212521 if (limb_tz != @sizeOf(Limb) * 8) break;
25222522 }
2523 return result;
2523 return @min(result, bits);
25242524 }
25252525};
25262526
src/value.zig+2-2
......@@ -1216,10 +1216,10 @@ pub const Value = struct {
12161216 return bigint.clz(ty.intInfo(mod).bits);
12171217 }
12181218
1219 pub fn ctz(val: Value, _: Type, mod: *Module) u64 {
1219 pub fn ctz(val: Value, ty: Type, mod: *Module) u64 {
12201220 var bigint_buf: BigIntSpace = undefined;
12211221 const bigint = val.toBigInt(&bigint_buf, mod);
1222 return bigint.ctz();
1222 return bigint.ctz(ty.intInfo(mod).bits);
12231223 }
12241224
12251225 pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {