# std.math: Add O\(log N\) implementation of log2\(x\) for comptime_int · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/70dc910086582b028d404d5de5049ceae0a95161)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 70dc910086582b028d404d5de5049ceae0a95161

Requested commit: 70dc910086582b028d404d5de5049ceae0a95161

Commit: 70dc910086582b028d404d5de5049ceae0a95161

Tree: 2d7f608a2a8021e3754695353e188222d040a553

Author: Cody Tapscott

Committer: Andrew Kelley

## Message

```
std.math: Add O(log N) implementation of log2(x) for comptime_int

Since Zig provides @clz and not @ffs (find-first-set), log2 for comptime
integers needs to be computed algorithmically. To avoid hitting the
backward branch quota, this updates log2(x) to use a simple O(log N)
algorithm.

```

## Parents

- [6ff7b437ff34e9a416a041c0c0ff8a65bae8daf5](https://git.cafe/gitcafe/zig/commit/6ff7b437ff34e9a416a041c0c0ff8a65bae8daf5?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/70dc910086582b028d404d5de5049ceae0a95161?format=markdown)
