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

master
Groove ago%!(EXTRA string=7 years)
parent 156ff1f4b2
commit 29f7e00e16
  1. 2
      test/core/core_func_geometric.cpp
  2. 7
      test/core/core_type_vec1.cpp

@ -169,7 +169,7 @@ namespace refract
glm::dvec2 A(0.0f,-1.0f); glm::dvec2 A(0.0f,-1.0f);
glm::dvec2 B(0.0f, 1.0f); glm::dvec2 B(0.0f, 1.0f);
glm::dvec2 C = glm::refract(A, B, 0.5); glm::dvec2 C = glm::refract(A, B, 0.5);
Error += C == glm::dvec2(0.0, -1.0) ? 0 : 1; Error += glm::all(glm::equal(C, glm::dvec2(0.0, -1.0), 0.0001)) ? 0 : 1;
} }
return Error; return Error;

@ -1,6 +1,7 @@
#define GLM_FORCE_SWIZZLE #define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp> #include <glm/gtc/constants.hpp>
#include <glm/gtc/vec1.hpp> #include <glm/ext/vector_relational.hpp>
#include <glm/ext/vec1.hpp>
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
#include <vector> #include <vector>
@ -136,7 +137,7 @@ static int test_swizzle()
glm::vec1 C(A.x); glm::vec1 C(A.x);
//Error += glm::all(glm::equal(A, B)) ? 0 : 1; //Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1; Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
} }
# endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR # endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR

Loading…
Cancel
Save