Checking if an Integer is an Exact Binary Power
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 25 12:37:45 PDT 2016
On 04/25/2016 03:21 PM, Solomon E wrote:
> I'm more concerned with getting the application
> logic right when I program than optimizing for speed or bytes, until
> something is noticeably pausing or taking extra megabytes.
This is a luxury not available to library writers.
> bool isPow2D(T)(T x)
> {
> return (x > 0) && !(x & (x - 1));
> }
This is worse than what we have now, which is easy to show is correct.
Andrei
More information about the Digitalmars-d
mailing list