Add ceilingPowerOf2

This commit is contained in:
Jack Andersen 2016-02-13 17:52:00 -10:00
parent 082cac124c
commit bbb81c96b8
2 changed files with 17 additions and 0 deletions

View File

@ -92,6 +92,7 @@ namespace Math
float fastCosR(float val);
float fastSinR(float val);
int floorPowerOfTwo(int x);
int ceilingPowerOfTwo(int x);
template <class T>
inline int PopCount(T x)

View File

@ -198,6 +198,22 @@ int floorPowerOfTwo(int x)
return x - (x >> 1);
}
int ceilingPowerOfTwo(int x)
{
if (x == 0)
return 0;
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
return x;
}
float fastCosR(float val)
{
if (fabs(val) > M_PI)