authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-06-06 22:41:55+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-06-06 22:41:55+12:00
log212449bc231047571ab27af0d1ae112ed0ffea47
treed8bf6682aad6b1a45743aad32558465514b7182e
parentd3693dca73dfc726aed32908691437abe614e5cf

Fix Log2Int type construction

The following case for example, would previously fail: const a = u24(1) << Log2Int(u24)(22);

1 files changed, 8 insertions(+), 1 deletions(-)

std/math/index.zig+8-1
......@@ -306,7 +306,14 @@ test "math.rotl" {
306306}
307307
308308pub 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
312319test "math overflow functions" {