MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / IsPowOfTwoUseLog

Function IsPowOfTwoUseLog

math/checkisnumberpoweroftwo.go:10–16  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

8// The limiting degree can be from 0 to 63.
9// See alternatives in the binary package.
10func 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}

Callers 2

TestIsPowOfTwoUseLogFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestIsPowOfTwoUseLogFunction · 0.68