| author | |
| committer | |
| log | 212449bc231047571ab27af0d1ae112ed0ffea47 |
| tree | d8bf6682aad6b1a45743aad32558465514b7182e |
| parent | d3693dca73dfc726aed32908691437abe614e5cf |
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" { |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | 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); | |
| 310 | 317 | } |
| 311 | 318 | |
| 312 | 319 | test "math overflow functions" { |