4 ms·
I'm not doing power == int(power) though which is what he warns against. I haven't done a lot of testing however as far I can tell it's working. >>> is_pow
by zxw 15y ago
I'm not doing power == int(power) though which is what he warns against. I haven't done a lot of testing however as far I can tell it's working.
>>> is_power_of_two(2 ** 31 - 1)
False
>>> is_power_of_two(2 ** 31)
True
>>> is_power_of_two(2 ** 31 + 1)
False
>>> is_power_of_two(2 ** 548 - 1)
False
>>> is_power_of_two(2 ** 548)
True
>>> is_power_of_two(2 ** 548 + 1)
False
- eru 15y agoYes. It seems to work for much larger numbers than this on my version of Python, but going via doubles leaves a bad taste.