mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
25 lines
485 B
Zig
25 lines
485 B
Zig
const assert = @import("std").debug.assert;
|
|
|
|
test "@popCount" {
|
|
comptime testPopCount();
|
|
testPopCount();
|
|
}
|
|
|
|
fn testPopCount() void {
|
|
{
|
|
var x: u32 = 0xaa;
|
|
assert(@popCount(x) == 4);
|
|
}
|
|
{
|
|
var x: u32 = 0xaaaaaaaa;
|
|
assert(@popCount(x) == 16);
|
|
}
|
|
{
|
|
var x: i16 = -1;
|
|
assert(@popCount(x) == 16);
|
|
}
|
|
comptime {
|
|
assert(@popCount(0b11111111000110001100010000100001000011000011100101010001) == 24);
|
|
}
|
|
}
|