Fixed error: comparing floating point with == or != is unsafe

This commit is contained in:
Groove 2018-07-28 14:28:49 +02:00
parent 0cd329da05
commit 6684535016
9 changed files with 53 additions and 78 deletions

View File

@ -65,8 +65,7 @@ int test_ctr()
glm::highp_mat2x2 const B(A);
glm::mediump_mat2x2 const C(B);
for(glm::length_t i = 0; i < A.length(); ++i)
Error += glm::all(glm::equal(A[i], C[i])) ? 0 : 1;
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
}
#if GLM_HAS_INITIALIZER_LISTS
@ -80,11 +79,8 @@ int test_ctr()
{0, 1},
{2, 3}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::mat2x2> v1{
{0, 1, 2, 3},
@ -118,8 +114,7 @@ namespace cast
glm::mat2 B(A);
glm::mat2 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
return Error;
}

View File

@ -1,4 +1,5 @@
#include <glm/vector_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat2x3.hpp>
#include <glm/mat2x4.hpp>
@ -44,11 +45,8 @@ int test_ctr()
{0, 1, 2},
{3, 4, 5}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::mat2x3> v1{
{0, 1, 2, 3, 4, 5},
@ -82,8 +80,7 @@ namespace cast
glm::mat2x3 B(A);
glm::mat2x3 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
return Error;
}

View File

@ -1,6 +1,6 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/vector_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat2x3.hpp>
#include <glm/mat2x4.hpp>
@ -46,11 +46,8 @@ int test_ctr()
{0, 1, 2, 3},
{4, 5, 6, 7}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::mat2x4> v1{
{0, 1, 2, 3, 4, 5, 6, 7},

View File

@ -1,4 +1,5 @@
#include <glm/vector_relational.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat2x3.hpp>
#include <glm/mat2x4.hpp>
@ -46,11 +47,8 @@ int test_ctr()
{2, 3},
{4, 5}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::mat3x2> v1{
{0, 1, 2, 3, 4, 5},
@ -86,8 +84,7 @@ namespace cast
glm::mat3x2 B(A);
glm::mat3x2 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
return Error;
}

View File

@ -1,4 +1,5 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/matrix.hpp>
#include <glm/vector_relational.hpp>
#include <glm/mat2x2.hpp>
@ -68,9 +69,9 @@ int test_inverse()
glm::mat3 const Inverse = glm::inverse(Matrix);
glm::mat3 const Identity = Matrix * Inverse;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::equal(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::equal(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::equal(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
}
{
@ -80,9 +81,9 @@ int test_inverse()
glm::vec3(0.3f, 0.5f, 0.7f));
glm::mat3 const Identity = Matrix / Matrix;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::equal(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::equal(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::equal(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
}
return Error;
@ -105,11 +106,8 @@ int test_ctr()
{3, 4, 5},
{6, 7, 8}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::mat3x3> v1{
{0, 1, 2, 3, 4, 5, 6, 7, 8},
@ -145,8 +143,7 @@ namespace cast
glm::mat3x3 B(A);
glm::mat3x3 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
return Error;
}

View File

@ -1,6 +1,6 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/vector_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat2x3.hpp>
#include <glm/mat2x4.hpp>
@ -48,11 +48,8 @@ int test_ctr()
{4, 5, 6, 7},
{8, 9, 10, 11}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::mat3x4> v1{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},

View File

@ -1,4 +1,5 @@
#include <glm/vector_relational.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat2x3.hpp>
#include <glm/mat2x4.hpp>
@ -48,11 +49,8 @@ int test_ctr()
{4, 5},
{6, 7}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::mat4x2> v1{
{0, 1, 2, 3, 4, 5, 6, 7},
@ -90,8 +88,7 @@ namespace cast
glm::mat4x2 B(A);
glm::mat4x2 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
return Error;
}

View File

@ -1,4 +1,5 @@
#include <glm/vector_relational.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat2x3.hpp>
#include <glm/mat2x4.hpp>
@ -90,8 +91,7 @@ namespace cast
glm::mat4x3 B(A);
glm::mat4x3 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
return Error;
}

View File

@ -209,11 +209,9 @@ int test_ctr()
{8, 9, 10, 11},
{12, 13, 14, 15}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat4> m3{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},