Fixed roundPowerOfTwo and floorPowerOfTwo #503
This commit is contained in:
parent
9770c9f73d
commit
76d12fb602
@ -30,8 +30,9 @@
|
|||||||
/// @author Christophe Riccio
|
/// @author Christophe Riccio
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
namespace glm
|
#include "../detail/func_integer.hpp"
|
||||||
{
|
|
||||||
|
namespace glm{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template <typename T, precision P, template <typename, precision> class vecType, bool compute = false>
|
template <typename T, precision P, template <typename, precision> class vecType, bool compute = false>
|
||||||
@ -275,7 +276,7 @@ namespace detail
|
|||||||
template <typename genType>
|
template <typename genType>
|
||||||
GLM_FUNC_QUALIFIER genType floorPowerOfTwo(genType value)
|
GLM_FUNC_QUALIFIER genType floorPowerOfTwo(genType value)
|
||||||
{
|
{
|
||||||
return isPowerOfTwo(value) ? value : highestBitValue(value);
|
return isPowerOfTwo(value) ? value : findMSB(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, precision P, template <typename, precision> class vecType>
|
template <typename T, precision P, template <typename, precision> class vecType>
|
||||||
@ -293,7 +294,7 @@ namespace detail
|
|||||||
if(isPowerOfTwo(value))
|
if(isPowerOfTwo(value))
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
genIUType const prev = highestBitValue(value);
|
genIUType const prev = findMSB(value);
|
||||||
genIUType const next = prev << 1;
|
genIUType const next = prev << 1;
|
||||||
return (next - value) < (value - prev) ? next : prev;
|
return (next - value) < (value - prev) ? next : prev;
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,32 @@ namespace ceilPowerOfTwo
|
|||||||
}
|
}
|
||||||
}//namespace ceilPowerOfTwo
|
}//namespace ceilPowerOfTwo
|
||||||
|
|
||||||
|
namespace roundPowerOfTwo
|
||||||
|
{
|
||||||
|
int test()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
glm::uint32 const A = glm::roundPowerOfTwo(7u);
|
||||||
|
Error += A == 8u ? 0 : 1;
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
}//namespace roundPowerOfTwo
|
||||||
|
|
||||||
|
namespace floorPowerOfTwo
|
||||||
|
{
|
||||||
|
int test()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
glm::uint32 const A = glm::floorPowerOfTwo(7u);
|
||||||
|
Error += A == 4u ? 0 : 1;
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
}//namespace floorPowerOfTwo
|
||||||
|
|
||||||
namespace floorMultiple
|
namespace floorMultiple
|
||||||
{
|
{
|
||||||
template <typename genType>
|
template <typename genType>
|
||||||
@ -380,6 +406,8 @@ int main()
|
|||||||
|
|
||||||
Error += isPowerOfTwo::test();
|
Error += isPowerOfTwo::test();
|
||||||
Error += ceilPowerOfTwo::test();
|
Error += ceilPowerOfTwo::test();
|
||||||
|
Error += floorPowerOfTwo::test();
|
||||||
|
Error += roundPowerOfTwo::test();
|
||||||
|
|
||||||
# ifdef NDEBUG
|
# ifdef NDEBUG
|
||||||
Error += ceilPowerOfTwo::perf();
|
Error += ceilPowerOfTwo::perf();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user