std.math.isPowerOf2

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 1 20:05:37 PDT 2016


Unsigned case is:
  return (x & -x) > (x - 1);

Wouldn't this be better:
  return (sz & (sz-1)) == 0;

I also don't understand the integer promotion and recursive call in
the integer case. Can someone explain how the std.math implementation
is ideal?


More information about the Digitalmars-d mailing list