From 76d12fb6025f1c8149bff3ba87266e6b003a260e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 29 Apr 2016 10:51:21 +0200 Subject: [PATCH] Fixed roundPowerOfTwo and floorPowerOfTwo #503 --- glm/gtc/round.inl | 9 +++++---- test/gtc/gtc_round.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/glm/gtc/round.inl b/glm/gtc/round.inl index 94fdd54b..c816089f 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 : findMSB(value); } template class vecType> @@ -293,7 +294,7 @@ namespace detail if(isPowerOfTwo(value)) return value; - genIUType const prev = highestBitValue(value); + genIUType const prev = findMSB(value); genIUType const next = prev << 1; return (next - value) < (value - prev) ? next : prev; } diff --git a/test/gtc/gtc_round.cpp b/test/gtc/gtc_round.cpp index aa6cf1a1..97b2abfd 100644 --- a/test/gtc/gtc_round.cpp +++ b/test/gtc/gtc_round.cpp @@ -294,6 +294,32 @@ 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 { template @@ -380,6 +406,8 @@ int main() Error += isPowerOfTwo::test(); Error += ceilPowerOfTwo::test(); + Error += floorPowerOfTwo::test(); + Error += roundPowerOfTwo::test(); # ifdef NDEBUG Error += ceilPowerOfTwo::perf();