| 85 | /** Returns whether `n` is a power of 2. */ |
| 86 | template <typename T> |
| 87 | bool isPow2(T n) { |
| 88 | return n > 0 && (n & (n - 1)) == 0; |
| 89 | } |
| 90 | |
| 91 | /** Returns 1 for positive numbers, -1 for negative numbers, and 0 for zero. |
| 92 | See https://en.wikipedia.org/wiki/Sign_function. |