Merge pull request #674 from decanus/patch-19

Update is_power_of_two to not use log2
This commit is contained in:
Danny Ryan 2019-02-22 07:11:46 -07:00 committed by GitHub
commit 59be8d8935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 4 deletions

View File

@ -1028,10 +1028,7 @@ def is_power_of_two(value: int) -> bool:
"""
Check if ``value`` is a power of two integer.
"""
if value == 0:
return False
else:
return 2**int(math.log2(value)) == value
return (value > 0) and (value & (value - 1) == 0)
```
### `int_to_bytes1`, `int_to_bytes2`, ...