Browse Source

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

Groove 7 years ago
parent
commit
3e364981e8
3 changed files with 8 additions and 7 deletions
  1. 1 0
      glm/gtc/quaternion.hpp
  2. 5 5
      glm/gtc/quaternion.inl
  3. 2 2
      test/ext/ext_vec1.cpp

+ 1 - 0
glm/gtc/quaternion.hpp

@@ -18,6 +18,7 @@
 #include "../mat4x4.hpp"
 #include "../vec3.hpp"
 #include "../vec4.hpp"
+#include "../ext/vector_relational.hpp"
 #include "../gtc/constants.hpp"
 #include "../gtc/matrix_transform.hpp"
 

+ 5 - 5
glm/gtc/quaternion.inl

@@ -603,13 +603,13 @@ namespace detail
 	GLM_FUNC_QUALIFIER T pitch(tquat<T, Q> const& q)
 	{
 		//return T(atan(T(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
-		const T y = static_cast<T>(2) * (q.y * q.z + q.w * q.x);
-		const T x = q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z;
+		T const y = static_cast<T>(2) * (q.y * q.z + q.w * q.x);
+		T const x = q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z;
 
-		if(detail::compute_equal<T, std::numeric_limits<T>::is_iec559>::call(y, static_cast<T>(0)) && detail::compute_equal<T, std::numeric_limits<T>::is_iec559>::call(x, static_cast<T>(0))) //avoid atan2(0,0) - handle singularity - Matiis
-			return static_cast<T>(static_cast<T>(2) * atan(q.x,q.w));
+		if(all(equal(vec<2, T, Q>(x, y), vec<2, T, Q>(0), epsilon<T>()))) //avoid atan2(0,0) - handle singularity - Matiis
+			return static_cast<T>(static_cast<T>(2) * atan(q.x, q.w));
 
-		return static_cast<T>(atan(y,x));
+		return static_cast<T>(atan(y, x));
 	}
 
 	template<typename T, qualifier Q>

+ 2 - 2
test/ext/ext_vec1.cpp

@@ -10,8 +10,8 @@ static int test_vec1_operators()
 {
 	int Error(0);
 
-	glm::ivec1 A(1.0f);
-	glm::ivec1 B(1.0f);
+	glm::ivec1 A(1);
+	glm::ivec1 B(1);
 	{
 		bool R = A != B;
 		bool S = A == B;