Fixed tests

This commit is contained in:
Christophe Riccio 2018-09-21 15:25:54 +02:00
parent 635ff4ef2d
commit d5df61aa66
3 changed files with 55 additions and 38 deletions

View File

@ -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<float_type>(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

View File

@ -1,4 +1,5 @@
#include <glm/ext/scalar_relational.hpp>
#include <glm/gtc/ulp.hpp>
#include <cmath>
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;

View File

@ -15,6 +15,7 @@
#include <glm/ext/vector_double3_precision.hpp>
#include <glm/ext/vector_double4.hpp>
#include <glm/ext/vector_double4_precision.hpp>
#include <glm/gtc/ulp.hpp>
template <typename vecType>
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 <typename T>
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<double>();
Error += test_notEqual_ulps<float>();
Error += test_notEqual_ulps<double>();
Error += test_equal<glm::vec1>();
Error += test_equal<glm::lowp_vec1>();
Error += test_equal<glm::mediump_vec1>();