Browse Source

Fixed roundPowerOfTwo and floorPowerOfTwo #503

Christophe Riccio 9 years ago
parent
commit
76d12fb602
2 changed files with 33 additions and 4 deletions
  1. 5 4
      glm/gtc/round.inl
  2. 28 0
      test/gtc/gtc_round.cpp

+ 5 - 4
glm/gtc/round.inl

@@ -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 : findMSB(value);
 	}
 
 	template <typename T, precision P, template <typename, precision> 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;
 	}

+ 28 - 0
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 <typename genType>
@@ -380,6 +406,8 @@ int main()
 
 	Error += isPowerOfTwo::test();
 	Error += ceilPowerOfTwo::test();
+	Error += floorPowerOfTwo::test();
+	Error += roundPowerOfTwo::test();
 
 #	ifdef NDEBUG
 		Error += ceilPowerOfTwo::perf();