From b3cae39ea66fd664e9c5dd64650a6820546d48c8 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 29 Apr 2016 17:37:27 +0200 Subject: [PATCH] Merge 0.9.7 --- glm/gtc/round.inl | 11 ++++--- readme.md | 1 + test/gtc/gtc_round.cpp | 73 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/glm/gtc/round.inl b/glm/gtc/round.inl index 94fdd54b..988c64a1 100644 --- a/glm/gtc/round.inl +++ b/glm/gtc/round.inl @@ -30,8 +30,9 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// -namespace glm -{ +#include "../detail/func_integer.hpp" + +namespace glm{ namespace detail { template class vecType, bool compute = false> @@ -275,7 +276,7 @@ namespace detail template GLM_FUNC_QUALIFIER genType floorPowerOfTwo(genType value) { - return isPowerOfTwo(value) ? value : highestBitValue(value); + return isPowerOfTwo(value) ? value : static_cast(1) << findMSB(value); } template 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(1) << findMSB(value); + genIUType const next = prev << static_cast(1); return (next - value) < (value - prev) ? next : prev; } diff --git a/readme.md b/readme.md index 2f11ca8d..227347eb 100644 --- a/readme.md +++ b/readme.md @@ -79,6 +79,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.7.5](https://github.com/g-truc/glm/tree/0.9.7) - 2016-0X-XX ##### Fixes: - Fixed uaddCarry warning #497 +- Fixed roundPowerOfTwo and floorPowerOfTwo #503 #### [GLM 0.9.7.4](https://github.com/g-truc/glm/releases/tag/0.9.7.4) - 2016-03-19 ##### Fixes: diff --git a/test/gtc/gtc_round.cpp b/test/gtc/gtc_round.cpp index 6e961e95..149f75cd 100644 --- a/test/gtc/gtc_round.cpp +++ b/test/gtc/gtc_round.cpp @@ -174,7 +174,7 @@ namespace isPowerOfTwo } }//isPowerOfTwo -namespace ceilPowerOfTwo +namespace ceilPowerOfTwo_advanced { template 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 @@ -406,8 +472,11 @@ 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(); # endif//NDEBUG