Merge pull request #2665 from koalazen/fix_math_is_power_of_two
fixes isPowerOfTwo returning true on the smallest integer
This commit is contained in:
commit
d882718882
1 changed files with 1 additions and 1 deletions
|
|
@ -85,7 +85,7 @@ proc fac*(n: int): int {.noSideEffect.} =
|
|||
proc isPowerOfTwo*(x: int): bool {.noSideEffect.} =
|
||||
## returns true, if `x` is a power of two, false otherwise.
|
||||
## Zero and negative numbers are not a power of two.
|
||||
return (x != 0) and ((x and (x - 1)) == 0)
|
||||
return (x > 0) and ((x and (x - 1)) == 0)
|
||||
|
||||
proc nextPowerOfTwo*(x: int): int {.noSideEffect.} =
|
||||
## returns `x` rounded up to the nearest power of two.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue