Jelajahi Sumber

Fixed ticket #182, isnan and isinf conflicts

Christophe Riccio 13 tahun lalu
induk
melakukan
a5fdf3c1bf
4 mengubah file dengan 85 tambahan dan 128 penghapusan
  1. 27 24
      glm/core/func_common.inl
  2. 0 10
      glm/gtx/compatibility.hpp
  3. 0 94
      glm/gtx/compatibility.inl
  4. 58 0
      test/core/core_func_common.cpp

+ 27 - 24
glm/core/func_common.inl

@@ -804,20 +804,21 @@ namespace detail
     }
 
 	template <typename genType> 
-	GLM_FUNC_QUALIFIER typename genType::bool_type isnan
-	(
-		genType const & x
-	)
+	GLM_FUNC_QUALIFIER bool isnan(genType const & x)
 	{
-		GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'mix' only accept floating-point inputs");
-
-#if(GLM_COMPILER & GLM_COMPILER_VC)
-		return typename genType::bool_type(_isnan(x));
-#elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
-		return typename genType::bool_type(::isnanf(x));
-#else
-		return typename genType::bool_type(std::isnan(x));
-#endif
+		GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'isnan' only accept floating-point inputs");
+
+#       if(GLM_COMPILER & GLM_COMPILER_VC)
+            return _isnan(x);
+#       elif(GLM_COMPILER & GLM_COMPILER_GCC)
+#           if(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
+                return _isnan(x) != 0;
+#           else
+                return std::isnan(x) != 0;
+#           endif
+#       else
+            return std::isnan(x) != 0;
+#       endif
 	}
 
     template <typename T>
@@ -857,20 +858,22 @@ namespace detail
     }
 
 	template <typename genType> 
-	GLM_FUNC_QUALIFIER typename genType::bool_type isinf
-	(
-		genType const & x
-	)
+	GLM_FUNC_QUALIFIER bool isinf(
+		genType const & x)
 	{
 		GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'isinf' only accept floating-point inputs");
 
-#if(GLM_COMPILER & GLM_COMPILER_VC)
-		return typename genType::bool_type(_fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF);
-#elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
-		return typename genType::bool_type(::__isinf(x));
-#else
-		return typename genType::bool_type(std::isinf(x));
-#endif
+#       if(GLM_COMPILER & GLM_COMPILER_VC)
+            return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF;
+#       elif(GLM_COMPILER & GLM_COMPILER_GCC)
+#           if(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
+                return _isinf(x) != 0;
+#           else
+                return std::isinf(x) != 0;
+#           endif
+#       else
+            return std::isinf(x) != 0;
+#       endif
 	}
 
     template <typename T>

+ 0 - 10
glm/gtx/compatibility.hpp

@@ -87,16 +87,6 @@ namespace glm
 	template <typename valType> detail::tvec3<bool> isfinite(const detail::tvec3<valType>& x);				//!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
 	template <typename valType> detail::tvec4<bool> isfinite(const detail::tvec4<valType>& x);				//!< \brief Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)
 
-	template <typename genType> bool isinf(genType const & x);														//!< \brief Determines whether the given floating-point value is infinite. (From GLM_GTX_compatibility extension) 
-	template <typename genType> detail::tvec2<bool> isinf(const detail::tvec2<genType>& x);					//!< \brief Determines whether the given floating-point value is infinite. (From GLM_GTX_compatibility extension) 
-	template <typename genType> detail::tvec3<bool> isinf(const detail::tvec3<genType>& x);					//!< \brief Determines whether the given floating-point value is infinite. (From GLM_GTX_compatibility extension) 
-	template <typename genType> detail::tvec4<bool> isinf(const detail::tvec4<genType>& x);					//!< \brief Determines whether the given floating-point value is infinite. (From GLM_GTX_compatibility extension) 
-
-	template <typename genType> bool isnan(genType const & x);														//!< \brief Checks given floating-point value for not a number (NAN) (From GLM_GTX_compatibility extension)
-	template <typename genType> detail::tvec2<bool> isnan(const detail::tvec2<genType>& x);					//!< \brief Checks given floating-point value for not a number (NAN) (From GLM_GTX_compatibility extension)
-	template <typename genType> detail::tvec3<bool> isnan(const detail::tvec3<genType>& x);					//!< \brief Checks given floating-point value for not a number (NAN) (From GLM_GTX_compatibility extension)
-	template <typename genType> detail::tvec4<bool> isnan(const detail::tvec4<genType>& x);					//!< \brief Checks given floating-point value for not a number (NAN) (From GLM_GTX_compatibility extension)
-
 	typedef bool						bool1;			//!< \brief boolean type with 1 component. (From GLM_GTX_compatibility extension)
 	typedef detail::tvec2<bool>			bool2;			//!< \brief boolean type with 2 components. (From GLM_GTX_compatibility extension)
 	typedef detail::tvec3<bool>			bool3;			//!< \brief boolean type with 3 components. (From GLM_GTX_compatibility extension)

+ 0 - 94
glm/gtx/compatibility.inl

@@ -58,98 +58,4 @@ namespace glm
 			isfinite(x.w));
 	}
 
-	// isinf
-	template <typename genType> 
-	GLM_FUNC_QUALIFIER bool isinf(
-		genType const & x)
-	{
-#       if(GLM_COMPILER & GLM_COMPILER_VC)
-            return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF;
-#       elif(GLM_COMPILER & GLM_COMPILER_GCC)
-#           if(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
-                return _isinf(x) != 0;
-#           else
-                return std::isinf(x) != 0;
-#           endif
-#       else
-            return std::isinf(x) != 0;
-#       endif
-	}
-
-	template <typename valType> 
-	GLM_FUNC_QUALIFIER detail::tvec2<bool> isinf(
-		detail::tvec2<valType> const & x)
-	{
-		return detail::tvec2<bool>(
-			isinf(x.x),
-			isinf(x.y));
-	}
-
-	template <typename valType> 
-	GLM_FUNC_QUALIFIER detail::tvec3<bool> isinf(
-		detail::tvec3<valType> const & x)
-	{
-		return detail::tvec3<bool>(
-			isinf(x.x),
-			isinf(x.y),
-			isinf(x.z));
-	}
-
-	template <typename valType> 
-	GLM_FUNC_QUALIFIER detail::tvec4<bool> isinf(
-		detail::tvec4<valType> const & x)
-	{
-		return detail::tvec4<bool>(
-			isinf(x.x),
-			isinf(x.y),
-			isinf(x.z),
-			isinf(x.w));
-	}
-
-	// isnan
-	template <typename genType> 
-	GLM_FUNC_QUALIFIER bool isnan(genType const & x)
-	{
-#       if(GLM_COMPILER & GLM_COMPILER_VC)
-            return _isnan(x);
-#       elif(GLM_COMPILER & GLM_COMPILER_GCC)
-#           if(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
-                return _isnan(x) != 0;
-#           else
-                return std::isnan(x) != 0;
-#           endif
-#       else
-            return std::isnan(x) != 0;
-#       endif
-	}
-
-	template <typename valType> 
-	GLM_FUNC_QUALIFIER detail::tvec2<bool> isnan(
-		detail::tvec2<valType> const & x)
-	{
-		return detail::tvec2<bool>(
-			isnan(x.x),
-			isnan(x.y));
-	}
-
-	template <typename valType> 
-	GLM_FUNC_QUALIFIER detail::tvec3<bool> isnan(
-		detail::tvec3<valType> const & x)
-	{
-		return detail::tvec3<bool>(
-			isnan(x.x),
-			isnan(x.y),
-			isnan(x.z));
-	}
-
-	template <typename valType> 
-	GLM_FUNC_QUALIFIER detail::tvec4<bool> isnan(
-		detail::tvec4<valType> const & x)
-	{
-		return detail::tvec4<bool>(
-			isnan(x.x),
-			isnan(x.y),
-			isnan(x.z),
-			isnan(x.w));
-	}
 }//namespace glm

+ 58 - 0
test/core/core_func_common.cpp

@@ -352,6 +352,62 @@ int test_roundEven()
 	return Error;
 }
 
+int test_isnan()
+{
+	int Error = 0;
+
+	float Zero_f = 0.0;
+	double Zero_d = 0.0;
+
+	{
+ 		Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
+ 		Error += true == glm::any(glm::isnan(glm::dvec2(0.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isnan(glm::dvec3(0.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isnan(glm::dvec4(0.0f/Zero_f))) ? 0 : 1;
+	}
+ 
+	{
+ 		Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
+ 		Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
+	}
+ 
+	return Error;
+}
+ 
+int test_isinf()
+{
+	int Error = 0;
+ 
+	float Zero_f = 0.0;
+	double Zero_d = 0.0;
+
+	{
+ 		Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
+		Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
+	}
+ 
+	{
+ 		Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
+ 		Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
+ 		Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
+	}
+ 
+	return Error;
+}
+
 int main()
 {
 	int Error(0);
@@ -362,6 +418,8 @@ int main()
 	Error += test_mix();
 	Error += test_round();
 	Error += test_roundEven();
+	Error += test_isnan();
+	Error += test_isinf();
 
 	return Error;
 }