Skip to content

Commit 212449b

Browse files
committedJun 6, 2018
Fix Log2Int type construction
The following case for example, would previously fail: const a = u24(1) << Log2Int(u24)(22);
·
0.15.20.3.0
1 parent d3693dc commit 212449b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎std/math/index.zig‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,14 @@ test "math.rotl" {
306306
}
307307

308308
pub fn Log2Int(comptime T: type) type {
309-
return @IntType(false, log2(T.bit_count));
309+
// comptime ceil log2
310+
comptime var count: usize = 0;
311+
comptime var s = T.bit_count - 1;
312+
inline while (s != 0) : (s >>= 1) {
313+
count += 1;
314+
}
315+
316+
return @IntType(false, count);
310317
}
311318

312319
test "math overflow functions" {

0 commit comments

Comments
 (0)
Please sign in to comment.