| 63 | /// Based-2 logarithm that works only on powers of two. |
| 64 | template <typename T> |
| 65 | constexpr T ReversePow2(T x) { |
| 66 | constexpr T kByteLen = 8; |
| 67 | for (T n = 0, y = 1; n <= (kByteLen * static_cast<T>(sizeof(T))); ++n, y = y * 2) { |
| 68 | if (y == x) { |
| 69 | return n; |
| 70 | } |
| 71 | } |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static_assert(ReversePow2(8) == 3); |
| 76 | static_assert(ReversePow2(4) == 2); |
no outgoing calls
no test coverage detected