From d5df61aa667c4ac98d970e64e324c621557f907e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 21 Sep 2018 15:25:54 +0200 Subject: [PATCH] Fixed tests --- glm/detail/type_float.hpp | 29 +++++++++++++++--- test/ext/ext_scalar_relational.cpp | 17 ++++++----- test/ext/ext_vector_relational.cpp | 47 +++++++++++++----------------- 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/glm/detail/type_float.hpp b/glm/detail/type_float.hpp index b1ea37f7..74bfc1ee 100644 --- a/glm/detail/type_float.hpp +++ b/glm/detail/type_float.hpp @@ -2,6 +2,12 @@ #include "setup.hpp" +#if GLM_COMPILER == GLM_COMPILER_VC12 +# pragma warning(push) +# pragma warning(disable: 2220) +# pragma warning(disable: 4512) // assignment operator could not be generated +#endif + namespace glm{ namespace detail { @@ -18,13 +24,19 @@ namespace detail GLM_CONSTEXPR float_t(float_type Num = 0.0f) : f(Num) {} + GLM_CONSTEXPR float_t& operator=(float_t const& x) + { + f = x.f; + return *this; + } + // Portable extraction of components. GLM_CONSTEXPR bool negative() const { return i < 0; } GLM_CONSTEXPR int_type mantissa() const { return i & ((1 << 23) - 1); } GLM_CONSTEXPR int_type exponent() const { return (i >> 23) & ((1 << 8) - 1); } - int_type const i; - float_type const f; + int_type i; + float_type f; }; template <> @@ -35,14 +47,23 @@ namespace detail GLM_CONSTEXPR float_t(float_type Num = static_cast(0)) : f(Num) {} + GLM_CONSTEXPR float_t& operator=(float_t const& x) + { + f = x.f; + return *this; + } + // Portable extraction of components. GLM_CONSTEXPR bool negative() const { return i < 0; } GLM_CONSTEXPR int_type mantissa() const { return i & ((int_type(1) << 52) - 1); } GLM_CONSTEXPR int_type exponent() const { return (i >> 52) & ((int_type(1) << 11) - 1); } - int_type const i; - float_type const f; + int_type i; + float_type f; }; }//namespace detail }//namespace glm +#if GLM_COMPILER == GLM_COMPILER_VC12 +# pragma warning(pop) +#endif diff --git a/test/ext/ext_scalar_relational.cpp b/test/ext/ext_scalar_relational.cpp index 53b4c9ee..88aa2578 100644 --- a/test/ext/ext_scalar_relational.cpp +++ b/test/ext/ext_scalar_relational.cpp @@ -1,4 +1,5 @@ #include +#include #include static int test_equal_epsilon() @@ -35,16 +36,16 @@ static int test_equal_ulps() { int Error = 0; - float const ULP1Plus = std::nextafter(1.0f, 2.0f); + float const ULP1Plus = glm::next_float(1.0f); Error += glm::equal(1.0f, ULP1Plus, 1) ? 0 : 1; - float const ULP2Plus = std::nextafter(ULP1Plus, 2.0f); + float const ULP2Plus = glm::next_float(ULP1Plus); Error += !glm::equal(1.0f, ULP2Plus, 1) ? 0 : 1; - float const ULP1Minus = std::nextafter(1.0f, 0.0f); + float const ULP1Minus = glm::prev_float(1.0f); Error += glm::equal(1.0f, ULP1Minus, 1) ? 0 : 1; - float const ULP2Minus = std::nextafter(ULP1Minus, 0.0f); + float const ULP2Minus = glm::prev_float(ULP1Minus); Error += !glm::equal(1.0f, ULP2Minus, 1) ? 0 : 1; return Error; @@ -54,16 +55,16 @@ static int test_notEqual_ulps() { int Error = 0; - float const ULP1Plus = std::nextafter(1.0f, 2.0f); + float const ULP1Plus = glm::next_float(1.0f); Error += !glm::notEqual(1.0f, ULP1Plus, 1) ? 0 : 1; - float const ULP2Plus = std::nextafter(ULP1Plus, 2.0f); + float const ULP2Plus = glm::next_float(ULP1Plus); Error += glm::notEqual(1.0f, ULP2Plus, 1) ? 0 : 1; - float const ULP1Minus = std::nextafter(1.0f, 0.0f); + float const ULP1Minus = glm::prev_float(1.0f); Error += !glm::notEqual(1.0f, ULP1Minus, 1) ? 0 : 1; - float const ULP2Minus = std::nextafter(ULP1Minus, 0.0f); + float const ULP2Minus = glm::prev_float(ULP1Minus); Error += glm::notEqual(1.0f, ULP2Minus, 1) ? 0 : 1; return Error; diff --git a/test/ext/ext_vector_relational.cpp b/test/ext/ext_vector_relational.cpp index df4d7bc4..deb0e800 100644 --- a/test/ext/ext_vector_relational.cpp +++ b/test/ext/ext_vector_relational.cpp @@ -15,6 +15,7 @@ #include #include #include +#include template static int test_equal() @@ -73,26 +74,23 @@ static int test_equal_ulps() { typedef glm::vec<4, T, glm::defaultp> vec4; - T const Zero(0); T const One(1); - T const Two(2); - vec4 const Ones(1); - + int Error = 0; - - T const ULP1Plus = std::nextafter(One, Two); + + T const ULP1Plus = glm::next_float(One); Error += glm::all(glm::equal(Ones, vec4(ULP1Plus), 1)) ? 0 : 1; - T const ULP2Plus = std::nextafter(ULP1Plus, Two); + T const ULP2Plus = glm::next_float(ULP1Plus); Error += !glm::all(glm::equal(Ones, vec4(ULP2Plus), 1)) ? 0 : 1; - - T const ULP1Minus = std::nextafter(One, Zero); + + T const ULP1Minus = glm::prev_float(One); Error += glm::all(glm::equal(Ones, vec4(ULP1Minus), 1)) ? 0 : 1; - T const ULP2Minus = std::nextafter(ULP1Minus, Zero); + T const ULP2Minus = glm::prev_float(ULP1Minus); Error += !glm::all(glm::equal(Ones, vec4(ULP2Minus), 1)) ? 0 : 1; - + return Error; } @@ -100,27 +98,24 @@ template static int test_notEqual_ulps() { typedef glm::vec<4, T, glm::defaultp> vec4; - - T const Zero(0); - T const One(1); - T const Two(2); + T const One(1); vec4 const Ones(1); - + int Error = 0; - - T const ULP1Plus = std::nextafter(One, Two); + + T const ULP1Plus = glm::next_float(One); Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Plus), 1)) ? 0 : 1; - - T const ULP2Plus = std::nextafter(ULP1Plus, Two); + + T const ULP2Plus = glm::next_float(ULP1Plus); Error += glm::all(glm::notEqual(Ones, vec4(ULP2Plus), 1)) ? 0 : 1; - - T const ULP1Minus = std::nextafter(One, Zero); + + T const ULP1Minus = glm::prev_float(One); Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Minus), 1)) ? 0 : 1; - - T const ULP2Minus = std::nextafter(ULP1Minus, Zero); + + T const ULP2Minus = glm::prev_float(ULP1Minus); Error += glm::all(glm::notEqual(Ones, vec4(ULP2Minus), 1)) ? 0 : 1; - + return Error; } @@ -132,7 +127,7 @@ int main() Error += test_equal_ulps(); Error += test_notEqual_ulps(); Error += test_notEqual_ulps(); - + Error += test_equal(); Error += test_equal(); Error += test_equal();