From 212449bc231047571ab27af0d1ae112ed0ffea47 Mon Sep 17 00:00:00 2001 From: Marc Tiehuis Date: Wed, 6 Jun 2018 22:41:55 +1200 Subject: [PATCH] Fix Log2Int type construction The following case for example, would previously fail: const a = u24(1) << Log2Int(u24)(22); --- std/math/index.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/std/math/index.zig b/std/math/index.zig index 33bc1082f7..a118f3ed47 100644 --- a/std/math/index.zig +++ b/std/math/index.zig @@ -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" {