Fixed merge

This commit is contained in:
Christophe Riccio 2016-04-30 16:28:20 +02:00
commit 306b409658
2 changed files with 77 additions and 7 deletions

View File

@ -30,8 +30,9 @@
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
#include "../detail/func_integer.hpp"
namespace glm{
namespace detail
{
template <typename T, precision P, template <typename, precision> class vecType, bool compute = false>
@ -275,7 +276,7 @@ namespace detail
template <typename genType>
GLM_FUNC_QUALIFIER genType floorPowerOfTwo(genType value)
{
return isPowerOfTwo(value) ? value : highestBitValue(value);
return isPowerOfTwo(value) ? value : static_cast<genType>(1) << findMSB(value);
}
template <typename T, precision P, template <typename, precision> class vecType>
@ -293,8 +294,8 @@ namespace detail
if(isPowerOfTwo(value))
return value;
genIUType const prev = highestBitValue(value);
genIUType const next = prev << 1;
genIUType const prev = static_cast<genIUType>(1) << findMSB(value);
genIUType const next = prev << static_cast<genIUType>(1);
return (next - value) < (value - prev) ? next : prev;
}

View File

@ -174,7 +174,7 @@ namespace isPowerOfTwo
}
}//isPowerOfTwo
namespace ceilPowerOfTwo
namespace ceilPowerOfTwo_advanced
{
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value)
@ -290,6 +290,72 @@ namespace ceilPowerOfTwo
Error += test_int32();
Error += test_uint32();
return Error;
}
}//namespace ceilPowerOfTwo_advanced
namespace roundPowerOfTwo
{
int test()
{
int Error = 0;
glm::uint32 const A = glm::roundPowerOfTwo(7u);
Error += A == 8u ? 0 : 1;
glm::uint32 const B = glm::roundPowerOfTwo(15u);
Error += B == 16u ? 0 : 1;
glm::uint32 const C = glm::roundPowerOfTwo(31u);
Error += C == 32u ? 0 : 1;
glm::uint32 const D = glm::roundPowerOfTwo(9u);
Error += D == 8u ? 0 : 1;
glm::uint32 const E = glm::roundPowerOfTwo(17u);
Error += E == 16u ? 0 : 1;
glm::uint32 const F = glm::roundPowerOfTwo(33u);
Error += F == 32u ? 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;
glm::uint32 const B = glm::floorPowerOfTwo(15u);
Error += B == 8u ? 0 : 1;
glm::uint32 const C = glm::floorPowerOfTwo(31u);
Error += C == 16u ? 0 : 1;
return Error;
}
}//namespace floorPowerOfTwo
namespace ceilPowerOfTwo
{
int test()
{
int Error = 0;
glm::uint32 const A = glm::ceilPowerOfTwo(7u);
Error += A == 8u ? 0 : 1;
glm::uint32 const B = glm::ceilPowerOfTwo(15u);
Error += B == 16u ? 0 : 1;
glm::uint32 const C = glm::ceilPowerOfTwo(31u);
Error += C == 32u ? 0 : 1;
return Error;
}
}//namespace ceilPowerOfTwo
@ -379,7 +445,10 @@ int main()
int Error(0);
Error += isPowerOfTwo::test();
Error += floorPowerOfTwo::test();
Error += roundPowerOfTwo::test();
Error += ceilPowerOfTwo::test();
Error += ceilPowerOfTwo_advanced::test();
# ifdef NDEBUG
Error += ceilPowerOfTwo::perf();