mirror of
https://github.com/ziglang/zig.git
synced 2025-12-27 16:43:07 +00:00
The test name here was likely the result of a bad copy-paste, as the test code is actually testing for trailing zeroes, not leading zeroes.
20 lines
632 B
Zig
20 lines
632 B
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
const math = std.math;
|
|
|
|
fn ctz(x: anytype) usize {
|
|
return @ctz(@TypeOf(x), x);
|
|
}
|
|
|
|
test "fixed" {
|
|
try testCtz();
|
|
comptime try testCtz();
|
|
}
|
|
|
|
fn testCtz() !void {
|
|
try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
|
|
try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
|
|
try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
|
|
try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
|
|
}
|