From cf68d926d89a806e9921ddc69ba813d953d4de11 Mon Sep 17 00:00:00 2001 From: Koala Zen Date: Wed, 6 May 2015 12:37:15 -0700 Subject: fixes isPowerOfTwo returning true on the smallest integer --- lib/pure/math.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/math.nim b/lib/pure/math.nim index daa108460..a5013a3ad 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -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. -- cgit 1.4.1-2-gfad0