MCPcopy Create free account
hub / github.com/apache/arrow / ReversePow2

Function ReversePow2

cpp/src/arrow/util/math_internal.h:65–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63/// Based-2 logarithm that works only on powers of two.
64template <typename T>
65constexpr 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
75static_assert(ReversePow2(8) == 3);
76static_assert(ReversePow2(4) == 2);

Callers 3

math_internal.hFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected