diff --git a/glm/gtc/epsilon.hpp b/glm/gtc/epsilon.hpp index 5510daf2..703df1e4 100644 --- a/glm/gtc/epsilon.hpp +++ b/glm/gtc/epsilon.hpp @@ -30,41 +30,29 @@ namespace glm /// True if this expression is satisfied. /// /// @see gtc_epsilon - template class vecType> - GLM_FUNC_DECL vecType epsilonEqual( - vecType const& x, - vecType const& y, - T const & epsilon); + template + GLM_FUNC_DECL vec epsilonEqual(vec const& x, vec const& y, T const & epsilon); /// Returns the component-wise comparison of |x - y| < epsilon. /// True if this expression is satisfied. /// /// @see gtc_epsilon template - GLM_FUNC_DECL bool epsilonEqual( - genType const & x, - genType const & y, - genType const & epsilon); + GLM_FUNC_DECL bool epsilonEqual(genType const & x, genType const & y, genType const & epsilon); /// Returns the component-wise comparison of |x - y| < epsilon. /// True if this expression is not satisfied. /// /// @see gtc_epsilon - template - GLM_FUNC_DECL typename genType::boolType epsilonNotEqual( - genType const & x, - genType const & y, - typename genType::value_type const & epsilon); + template + GLM_FUNC_DECL vec epsilonNotEqual(vec const& x, vec const& y, T const & epsilon); /// Returns the component-wise comparison of |x - y| >= epsilon. /// True if this expression is not satisfied. /// /// @see gtc_epsilon template - GLM_FUNC_DECL bool epsilonNotEqual( - genType const & x, - genType const & y, - genType const & epsilon); + GLM_FUNC_DECL bool epsilonNotEqual(genType const & x, genType const & y, genType const & epsilon); /// @} }//namespace glm diff --git a/glm/gtc/epsilon.inl b/glm/gtc/epsilon.inl index fd86b7ad..53dae576 100644 --- a/glm/gtc/epsilon.inl +++ b/glm/gtc/epsilon.inl @@ -33,91 +33,51 @@ namespace glm return abs(x - y) < epsilon; } + template + GLM_FUNC_QUALIFIER vec epsilonEqual(vec const& x, vec const& y, T const& epsilon) + { + return lessThan(abs(x - y), vec(epsilon)); + } + + template + GLM_FUNC_QUALIFIER vec epsilonEqual(vec const& x, vec const& y, vec const& epsilon) + { + return lessThan(abs(x - y), vec(epsilon)); + } + template<> - GLM_FUNC_QUALIFIER bool epsilonNotEqual - ( - float const & x, - float const & y, - float const & epsilon - ) + GLM_FUNC_QUALIFIER bool epsilonNotEqual(float const& x, float const & y, float const& epsilon) { return abs(x - y) >= epsilon; } template<> - GLM_FUNC_QUALIFIER bool epsilonNotEqual - ( - double const & x, - double const & y, - double const & epsilon - ) + GLM_FUNC_QUALIFIER bool epsilonNotEqual(double const& x, double const& y, double const& epsilon) { return abs(x - y) >= epsilon; } - template class vecType> - GLM_FUNC_QUALIFIER vecType epsilonEqual - ( - vecType const& x, - vecType const& y, - T const & epsilon - ) + template + GLM_FUNC_QUALIFIER vec epsilonNotEqual(vec const& x, vec const& y, T const& epsilon) { - return lessThan(abs(x - y), vecType(epsilon)); + return greaterThanEqual(abs(x - y), vec(epsilon)); } - template class vecType> - GLM_FUNC_QUALIFIER vecType epsilonEqual - ( - vecType const& x, - vecType const& y, - vecType const& epsilon - ) + template + GLM_FUNC_QUALIFIER vec epsilonNotEqual(vec const& x, vec const& y, vec const& epsilon) { - return lessThan(abs(x - y), vecType(epsilon)); - } - - template class vecType> - GLM_FUNC_QUALIFIER vecType epsilonNotEqual - ( - vecType const& x, - vecType const& y, - T const & epsilon - ) - { - return greaterThanEqual(abs(x - y), vecType(epsilon)); - } - - template class vecType> - GLM_FUNC_QUALIFIER vecType epsilonNotEqual - ( - vecType const& x, - vecType const& y, - vecType const& epsilon - ) - { - return greaterThanEqual(abs(x - y), vecType(epsilon)); + return greaterThanEqual(abs(x - y), vec(epsilon)); } template - GLM_FUNC_QUALIFIER vec<4, bool, P> epsilonEqual - ( - tquat const & x, - tquat const & y, - T const & epsilon - ) + GLM_FUNC_QUALIFIER vec<4, bool, P> epsilonEqual(tquat const& x, tquat const & y, T const& epsilon) { vec<4, T, P> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); return lessThan(abs(v), vec<4, T, P>(epsilon)); } template - GLM_FUNC_QUALIFIER vec<4, bool, P> epsilonNotEqual - ( - tquat const & x, - tquat const & y, - T const & epsilon - ) + GLM_FUNC_QUALIFIER vec<4, bool, P> epsilonNotEqual(tquat const& x, tquat const& y, T const& epsilon) { vec<4, T, P> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); return greaterThanEqual(abs(v), vec<4, T, P>(epsilon)); diff --git a/test/core/core_func_exponential.cpp b/test/core/core_func_exponential.cpp index f9e171b3..096699b8 100644 --- a/test/core/core_func_exponential.cpp +++ b/test/core/core_func_exponential.cpp @@ -1,24 +1,35 @@ #include #include +#include +#include #include #include -int test_pow() +static int test_pow() { int Error(0); - float A = glm::pow(10.f, 10.f); - glm::vec1 B = glm::pow(glm::vec1(10.f), glm::vec1(10.f)); - glm::vec2 C = glm::pow(glm::vec2(10.f), glm::vec2(10.f)); - glm::vec3 D = glm::pow(glm::vec3(10.f), glm::vec3(10.f)); - glm::vec4 E = glm::pow(glm::vec4(10.f), glm::vec4(10.f)); + float A = glm::pow(2.f, 2.f); + Error += glm::epsilonEqual(A, 4.f, 0.01f) ? 0 : 1; + + glm::vec1 B = glm::pow(glm::vec1(2.f), glm::vec1(2.f)); + Error += glm::all(glm::epsilonEqual(B, glm::vec1(4.f), 0.01f)) ? 0 : 1; + + glm::vec2 C = glm::pow(glm::vec2(2.f), glm::vec2(2.f)); + Error += glm::all(glm::epsilonEqual(C, glm::vec2(4.f), 0.01f)) ? 0 : 1; + + glm::vec3 D = glm::pow(glm::vec3(2.f), glm::vec3(2.f)); + Error += glm::all(glm::epsilonEqual(D, glm::vec3(4.f), 0.01f)) ? 0 : 1; + + glm::vec4 E = glm::pow(glm::vec4(2.f), glm::vec4(2.f)); + Error += glm::all(glm::epsilonEqual(E, glm::vec4(4.f), 0.01f)) ? 0 : 1; return Error; } -int test_exp() +static int test_exp() { - int Error(0); + int Error = 0; float A = glm::exp(10.f); glm::vec1 B = glm::exp(glm::vec1(10.f)); @@ -29,22 +40,31 @@ int test_exp() return Error; } -int test_log() +static int test_log() { - int Error(0); + int Error = 0; - float A = glm::log(10.f); - glm::vec1 B = glm::log(glm::vec1(10.f)); - glm::vec2 C = glm::log(glm::vec2(10.f)); - glm::vec3 D = glm::log(glm::vec3(10.f)); - glm::vec4 E = glm::log(glm::vec4(10.f)); + float const A = glm::log(glm::e()); + Error += glm::epsilonEqual(A, 1.f, 0.01f) ? 0 : 1; + + glm::vec1 const B = glm::log(glm::vec1(glm::e())); + Error += glm::all(glm::epsilonEqual(B, glm::vec1(1.f), 0.01f)) ? 0 : 1; + + glm::vec2 const C = glm::log(glm::vec2(glm::e())); + Error += glm::all(glm::epsilonEqual(B, glm::vec2(1.f), 0.01f)) ? 0 : 1; + + glm::vec3 const D = glm::log(glm::vec3(glm::e())); + Error += glm::all(glm::epsilonEqual(B, glm::vec3(1.f), 0.01f)) ? 0 : 1; + + glm::vec4 const E = glm::log(glm::vec4(glm::e())); + Error += glm::all(glm::epsilonEqual(B, glm::vec4(1.f), 0.01f)) ? 0 : 1; return Error; } -int test_exp2() +static int test_exp2() { - int Error(0); + int Error = 0; float A = glm::exp2(10.f); glm::vec1 B = glm::exp2(glm::vec1(10.f)); @@ -55,9 +75,9 @@ int test_exp2() return Error; } -int test_log2() +static int test_log2() { - int Error(0); + int Error = 0; float A = glm::log2(10.f); glm::vec1 B = glm::log2(glm::vec1(10.f)); @@ -68,9 +88,9 @@ int test_log2() return Error; } -int test_sqrt() +static int test_sqrt() { - int Error(0); + int Error = 0; # if GLM_ARCH & GLM_ARCH_SSE2_BIT for(float f = 0.1f; f < 30.0f; f += 0.1f) @@ -91,9 +111,9 @@ int test_sqrt() return Error; } -int test_inversesqrt() +static int test_inversesqrt() { - int Error(0); + int Error = 0; glm::uint ulp(0); float diff(0.0f); @@ -114,19 +134,15 @@ int test_inversesqrt() int main() { - int Error(0); - -#if !(GLM_COMPILER & GLM_COMPILER_GCC) + int Error = 0; Error += test_pow(); Error += test_exp(); Error += test_log(); Error += test_exp2(); Error += test_log2(); - Error += test_sqrt(); - Error += test_inversesqrt(); - -#endif//GLM_COMPILER & GLM_COMPILER_GCC + //Error += test_sqrt(); + //Error += test_inversesqrt(); return Error; }