Skip to content

Commit

Permalink
Fix Log2Int type construction
Browse files Browse the repository at this point in the history
The following case for example, would previously fail:

    const a = u24(1) << Log2Int(u24)(22);
  • Loading branch information
tiehuis committed Jun 6, 2018
1 parent d3693dc commit 212449b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion std/math/index.zig
Expand Up @@ -306,7 +306,14 @@ test "math.rotl" {
}

pub fn Log2Int(comptime T: type) type {
return @IntType(false, log2(T.bit_count));
// comptime ceil log2
comptime var count: usize = 0;
comptime var s = T.bit_count - 1;
inline while (s != 0) : (s >>= 1) {
count += 1;
}

return @IntType(false, count);
}

test "math overflow functions" {
Expand Down

0 comments on commit 212449b

Please sign in to comment.