Checking if an Integer is an Exact Binary Power

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 23 23:57:04 PDT 2016


On Saturday, 23 April 2016 at 15:29:08 UTC, Andrei Alexandrescu 
wrote:
> Yah, that's the canonical. I forgot why I chose (x & -x) > (x - 
> 1) over it.

I'm not sure why do you test against x - 1 when you could test 
for equality. Not only it looks like it is going to require an 
extra computation (x - 1) but also it doesn't work for 0.


More information about the Digitalmars-d mailing list