Fixed log2

This commit is contained in:
Christophe Riccio 2011-10-11 20:05:08 +01:00
parent 3c2882439f
commit 8864136e87
2 changed files with 14 additions and 23 deletions

View File

@ -55,31 +55,22 @@ namespace detail
}
}//namespace detail
#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC))
GLM_FUNC_QUALIFIER unsigned int log2(unsigned int x)
{
return x <= 1 ? 0 : unsigned(32) - nlz(x - 1u);
}
#else
GLM_FUNC_QUALIFIER unsigned int log2(unsigned int x)
{
return unsigned(32) - nlz(x - 1u);
//if(x <= 1)
// return 0;
//return unsigned(32) - findLSB(x) - 1u;
/*
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
register int y = (x & (x - 1));
y |= -y;
y >>= (WORDBITS - 1);
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return detail::ones32(x) - 1 - y;
*/
}
#endif
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
unsigned int floor_log2(unsigned int x)
{
@ -172,7 +163,7 @@ GLM_FUNC_QUALIFIER uint mod(uint x, uint y)
GLM_FUNC_QUALIFIER unsigned int nlz(unsigned int x)
{
return 32u - findMSB(x);
return 31u - findMSB(x);
}
#else

View File

@ -38,7 +38,7 @@ int test_log2()
double B = glm::log2(double(i));
Error += glm::equalEpsilon(double(A), B, 1.0) ? 0 : 1;
assert(!Error);
//assert(!Error);
}
return Error;
@ -49,7 +49,7 @@ int test_nlz()
int Error = 0;
for(std::size_t i = 1; i < 33; ++i)
printf("%d, %d\n", glm::nlz(i), 31 - glm::findMSB(i));
printf("%d, %d\n", glm::nlz(i), 31u - glm::findMSB(i));
return Error;
}