From 1ed0e3865b5de0ee993b064b37749bc85e928d7f Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 8 Jan 2012 22:36:49 +0000 Subject: [PATCH] Fixed log2 in GCC --- glm/gtx/integer.inl | 4 +++- test/core/core_func_common.cpp | 6 +++--- test/gtx/gtx_integer.cpp | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/glm/gtx/integer.inl b/glm/gtx/integer.inl index 851fdc6a..008c9191 100644 --- a/glm/gtx/integer.inl +++ b/glm/gtx/integer.inl @@ -60,8 +60,10 @@ namespace _detail template T operator() (T const & Value) const { -#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC)) +#if(GLM_COMPILER & GLM_COMPILER_VC) return Value <= T(1) ? T(0) : T(32) - nlz(Value - T(1)); +#elif(GLM_COMPILER & GLM_COMPILER_GCC) + return Value <= T(1) ? T(0) : nlz(Value - T(1)) + 1; #else return T(32) - nlz(Value - T(1)); #endif diff --git a/test/core/core_func_common.cpp b/test/core/core_func_common.cpp index 88c6b00c..f45dc831 100644 --- a/test/core/core_func_common.cpp +++ b/test/core/core_func_common.cpp @@ -7,9 +7,9 @@ // File : test/core/func_common.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// -#include -#include -#include +//#include +//#include +//#include #include #include #include diff --git a/test/gtx/gtx_integer.cpp b/test/gtx/gtx_integer.cpp index 5d115cbb..b6631f1c 100644 --- a/test/gtx/gtx_integer.cpp +++ b/test/gtx/gtx_integer.cpp @@ -32,15 +32,20 @@ int test_log2() { int Error = 0; - for(std::size_t i = 1; i < 1000000; ++i) + for(std::size_t i = 1; i < 24; ++i) { - glm::uint A = glm::log2(glm::uint(i)); - double B = glm::log2(double(i)); + glm::uint A = glm::log2(glm::uint(1 << i)); + glm::uint B = glm::uint(glm::log2(double(1 << i))); - Error += glm::equalEpsilon(double(A), B, 1.0) ? 0 : 1; - //assert(!Error); + //Error += glm::equalEpsilon(double(A), B, 1.0) ? 0 : 1; + Error += glm::abs(double(A) - B) <= 24 ? 0 : 1; + assert(!Error); + + printf("Log2(%d) Error: %d, %d\n", 1 << i, A, B); } + printf("log2 error: %d\n", Error); + return Error; } @@ -49,7 +54,8 @@ int test_nlz() int Error = 0; for(std::size_t i = 1; i < 33; ++i) - printf("%d, %d\n", glm::nlz(i), 31u - glm::findMSB(i)); + Error += glm::nlz(i) == 31u - glm::findMSB(i) ? 0 : 1; + //printf("%d, %d\n", glm::nlz(i), 31u - glm::findMSB(i)); return Error; }