Merge pull request #4327 from tsbockman/isPowerOf2

Add `std.math.isPowerOf2()`. Supports floating-point and integers.
This commit is contained in:
Andrei Alexandrescu 2016-06-16 23:09:02 -04:00 committed by GitHub
commit 7172eda466
8 changed files with 131 additions and 46 deletions

View file

@ -4632,7 +4632,8 @@ if (isForwardRange!R && !isRandomAccessRange!R)
private auto sumPairwiseN(size_t N, bool needEmptyChecks, F, R)(ref R r)
if (isForwardRange!R && !isRandomAccessRange!R)
{
static assert(!(N & (N-1))); //isPow2
import std.math : isPowerOf2;
static assert(isPowerOf2(N));
static if (N == 2) return sumPair!(needEmptyChecks, F)(r);
else return sumPairwiseN!(N/2, needEmptyChecks, F)(r)
+ sumPairwiseN!(N/2, needEmptyChecks, F)(r);