From 7cd97fe610ab47ce01afeeaece63f7210e2cb4a3 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 16 Sep 2011 09:39:51 +0100 Subject: [PATCH] Fixed and test round functions --- glm/core/func_common.inl | 2 + test/core/core_func_common.cpp | 72 ++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/glm/core/func_common.inl b/glm/core/func_common.inl index 49073cbc..e3f9bd2d 100644 --- a/glm/core/func_common.inl +++ b/glm/core/func_common.inl @@ -237,6 +237,8 @@ namespace detail { GLM_STATIC_ASSERT(detail::type::is_float, "'round' only accept floating-point inputs"); + if(x < 0) + return genType(int(x - genType(0.5))); return genType(int(x + genType(0.5))); } diff --git a/test/core/core_func_common.cpp b/test/core/core_func_common.cpp index 0ec771fe..e13000cc 100644 --- a/test/core/core_func_common.cpp +++ b/test/core/core_func_common.cpp @@ -136,23 +136,86 @@ int test_round() Error += D == 0.0f ? 0 : 1; float E = glm::round(0.9f); Error += E == 1.0f ? 0 : 1; - float F = glm::round(1.9f); + float F = glm::round(1.5f); Error += F == 2.0f ? 0 : 1; + float G = glm::round(1.9f); + Error += G == 2.0f ? 0 : 1; } { float A = glm::round(-0.0f); - Error += A == 0.0f ? 0 : 1; + Error += A == 0.0f ? 0 : 1; float B = glm::round(-0.5f); Error += B == -1.0f ? 0 : 1; float C = glm::round(-1.0f); Error += C == -1.0f ? 0 : 1; float D = glm::round(-0.1f); - Error += D == 0.0f ? 0 : 1; + Error += D == 0.0f ? 0 : 1; float E = glm::round(-0.9f); Error += E == -1.0f ? 0 : 1; - float F = glm::round(-1.9f); + float F = glm::round(-1.5f); Error += F == -2.0f ? 0 : 1; + float G = glm::round(-1.9f); + Error += G == -2.0f ? 0 : 1; + } + + return Error; +} + +int test_roundEven() +{ + int Error = 0; + + { + float A = glm::roundEven(0.0f); + Error += A == 0.0f ? 0 : 1; + float B = glm::roundEven(0.5f); + Error += B == 0.0f ? 0 : 1; + float C = glm::roundEven(1.0f); + Error += C == 2.0f ? 0 : 1; + float D = glm::roundEven(0.1f); + Error += D == 0.0f ? 0 : 1; + float E = glm::roundEven(0.9f); + Error += E == 0.0f ? 0 : 1; + float F = glm::roundEven(1.9f); + Error += F == 2.0f ? 0 : 1; + float G = glm::roundEven(2.5f); + Error += G == 2.0f ? 0 : 1; + float H = glm::roundEven(2.9f); + Error += H == 2.0f ? 0 : 1; + float I = glm::roundEven(3.2f); + Error += I == 4.0f ? 0 : 1; + float J = glm::roundEven(3.5f); + Error += J == 4.0f ? 0 : 1; + float K = glm::roundEven(3.9f); + Error += K == 4.0f ? 0 : 1; + float L = glm::roundEven(4.1f); + Error += L == 4.0f ? 0 : 1; + } + + { + float A = glm::roundEven(-0.0f); + Error += A == 0.0f ? 0 : 1; + float B = glm::roundEven(-0.5f); + Error += B == -2.0f ? 0 : 1; + float C = glm::roundEven(-1.0f); + Error += C == -2.0f ? 0 : 1; + float D = glm::roundEven(-0.1f); + Error += D == 0.0f ? 0 : 1; + float E = glm::roundEven(-0.9f); + Error += E == -2.0f ? 0 : 1; + float F = glm::roundEven(-1.9f); + Error += F == -2.0f ? 0 : 1; + float G = glm::roundEven(-2.5f); + Error += G == -2.0f ? 0 : 1; + float H = glm::roundEven(-2.9f); + Error += H == -2.0f ? 0 : 1; + float I = glm::roundEven(-3.2f); + Error += I == -4.0f ? 0 : 1; + float J = glm::roundEven(-3.5f); + Error += J == -4.0f ? 0 : 1; + float K = glm::roundEven(-3.9f); + Error += K == -4.0f ? 0 : 1; } return Error; @@ -166,6 +229,7 @@ int main() Error += test_floatBitsToUint(); Error += test_mix(); Error += test_round(); + Error += test_roundEven(); return Error; }