mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
math.big.int: fix ctz of zero
This commit is contained in:
parent
d019229c2c
commit
26fac15f48
@ -2512,7 +2512,7 @@ pub const Const = struct {
|
||||
return total_limb_lz + bits - total_limb_bits;
|
||||
}
|
||||
|
||||
pub fn ctz(a: Const) Limb {
|
||||
pub fn ctz(a: Const, bits: Limb) Limb {
|
||||
// Limbs are stored in little-endian order.
|
||||
var result: Limb = 0;
|
||||
for (a.limbs) |limb| {
|
||||
@ -2520,7 +2520,7 @@ pub const Const = struct {
|
||||
result += limb_tz;
|
||||
if (limb_tz != @sizeOf(Limb) * 8) break;
|
||||
}
|
||||
return result;
|
||||
return @min(result, bits);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1216,10 +1216,10 @@ pub const Value = struct {
|
||||
return bigint.clz(ty.intInfo(mod).bits);
|
||||
}
|
||||
|
||||
pub fn ctz(val: Value, _: Type, mod: *Module) u64 {
|
||||
pub fn ctz(val: Value, ty: Type, mod: *Module) u64 {
|
||||
var bigint_buf: BigIntSpace = undefined;
|
||||
const bigint = val.toBigInt(&bigint_buf, mod);
|
||||
return bigint.ctz();
|
||||
return bigint.ctz(ty.intInfo(mod).bits);
|
||||
}
|
||||
|
||||
pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user