Checking if an Integer is an Exact Binary Power
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sat Apr 23 06:41:35 PDT 2016
On 4/23/16 9:04 AM, Nordlöw wrote:
> Wanted: CT-trait and run-time predicate for checking whether its single
> integer parameter is an exact power of two.
>
> I guess
>
> https://dlang.org/phobos/std_math.html#.truncPow2
>
> or
>
> https://dlang.org/phobos/std_math.html#.nextPow2
>
> could be reused, but I bet there's a more efficient way of checking this.
There's stuff for that in e.g.
https://github.com/dlang/phobos/blob/master/std/experimental/allocator/common.d#L462.
They're package-private with the intent is to move those slowly into
Phobos. -- Andrei
More information about the Digitalmars-d
mailing list