3 ms·
math.log uses floating point arithmetic. That will lead to trouble on large numbers. The article addresses the issue.
by eru 15y ago
math.log uses floating point arithmetic. That will lead to trouble on large numbers. The article addresses the issue.
- zxw 15y agoI'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.