diff --git a/glm/detail/func_common.inl b/glm/detail/func_common.inl index 9c55c7a1..6d021e2b 100644 --- a/glm/detail/func_common.inl +++ b/glm/detail/func_common.inl @@ -156,16 +156,20 @@ namespace detail GLM_FUNC_QUALIFIER genFIType sign(genFIType x) { GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559 || - (std::numeric_limits::is_signed && std::numeric_limits::is_integer), "'sign' only accept signed inputs"); + std::numeric_limits::is_iec559 || (std::numeric_limits::is_signed && std::numeric_limits::is_integer), + "'sign' only accept signed inputs"); - return genFIType(genFIType(0) < x) - (x < genFIType(0)); + return static_cast(static_cast(0) < x) - static_cast(x < static_cast(0)); } template class vecType> GLM_FUNC_QUALIFIER vecType sign(vecType const & x) { - return detail::functor1::call(sign, x); + GLM_STATIC_ASSERT( + std::numeric_limits::is_iec559 || (std::numeric_limits::is_signed && std::numeric_limits::is_integer), + "'sign' only accept signed inputs"); + + return vecType(glm::lessThan(vecType(0), x)) - vecType(glm::lessThan(x, vecType(0))); } // floor diff --git a/test/core/core_func_common.cpp b/test/core/core_func_common.cpp index 83fba5f6..9dee633f 100644 --- a/test/core/core_func_common.cpp +++ b/test/core/core_func_common.cpp @@ -855,6 +855,12 @@ namespace sign int Error = 0; + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type); ++i) + { + glm::int32 Result = glm::sign(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type); ++i) { glm::int32 Result = sign_cmp(Data[i].Value); @@ -888,11 +894,36 @@ namespace sign return Error; } + int test_i32vec4() + { + type const Data[] = + { + {glm::i32vec4( 1), glm::i32vec4( 1)}, + {glm::i32vec4( 0), glm::i32vec4( 0)}, + {glm::i32vec4( 2), glm::i32vec4( 1)}, + {glm::i32vec4( 3), glm::i32vec4( 1)}, + {glm::i32vec4(-1), glm::i32vec4(-1)}, + {glm::i32vec4(-2), glm::i32vec4(-1)}, + {glm::i32vec4(-3), glm::i32vec4(-1)} + }; + + int Error = 0; + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type); ++i) + { + glm::i32vec4 Result = glm::sign(Data[i].Value); + Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1; + } + + return Error; + } + int test() { int Error = 0; Error += test_int32(); + Error += test_i32vec4(); return Error; }