Skip to content

Commit 0c7ba70

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 291558d commit 0c7ba70

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bit_manipulation/is_power_of_two.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ def is_power_of_two(number: int) -> bool:
6464
raise ValueError("number must not be negative")
6565
return number & (number - 1) == 0
6666

67+
6768
def is_power_of_two_math(number: int) -> bool:
6869
from math import log2
70+
6971
"""
7072
Alternative method using math.log2 to check if number is a power of 2.
71-
73+
7274
>>> is_power_of_two_math(0)
7375
True
7476
>>> is_power_of_two_math(1)
@@ -84,15 +86,15 @@ def is_power_of_two_math(number: int) -> bool:
8486
raise TypeError("number must be an integer")
8587
if number < 0:
8688
raise ValueError("number must not be negative")
87-
89+
8890
if number == 0:
8991
return True
90-
92+
9193
value = log2(number)
9294
return value == int(value)
9395

96+
9497
if __name__ == "__main__":
9598
import doctest
9699

97100
doctest.testmod()
98-

0 commit comments

Comments
 (0)