IsPowOfTwoUseLog This function checks if a number is a power of two using the logarithm. The limiting degree can be from 0 to 63. See alternatives in the binary package.
(number float64)
| 8 | // The limiting degree can be from 0 to 63. |
| 9 | // See alternatives in the binary package. |
| 10 | func IsPowOfTwoUseLog(number float64) bool { |
| 11 | if number == 0 || math.Round(number) == math.MaxInt64 { |
| 12 | return false |
| 13 | } |
| 14 | log := math.Log2(number) |
| 15 | return log == math.Round(log) |
| 16 | } |
no outgoing calls