소스 검색

Fixed epsilon for half types

Christophe Riccio 13 년 전
부모
커밋
bfec0e2388
4개의 변경된 파일21개의 추가작업 그리고 13개의 파일을 삭제
  1. 7 7
      glm/core/type_half.inl
  2. 6 0
      glm/gtc/constants.inl
  3. 3 1
      test/gtc/gtc_constants.cpp
  4. 5 5
      test/gtc/gtc_epsilon.cpp

+ 7 - 7
glm/core/type_half.inl

@@ -2,6 +2,10 @@
 /// OpenGL Mathematics (glm.g-truc.net)
 ///
 /// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
+///
+/// This half implementation is based on OpenEXR which is Copyright (c) 2002, 
+/// Industrial Light & Magic, a division of Lucas Digital Ltd. LLC
+///
 /// Permission is hereby granted, free of charge, to any person obtaining a copy
 /// of this software and associated documentation files (the "Software"), to deal
 /// in the Software without restriction, including without limitation the rights
@@ -24,10 +28,6 @@
 /// @file glm/core/type_half.inl
 /// @date 2008-08-17 / 2011-06-15
 /// @author Christophe Riccio
-///
-/// Copyright:
-/// This half implementation is based on OpenEXR which is Copyright (c) 2002, 
-/// Industrial Light & Magic, a division of Lucas Digital Ltd. LLC
 ///////////////////////////////////////////////////////////////////////////////////
 
 #include "_detail.hpp"
@@ -152,7 +152,7 @@ namespace detail
 				// less than half_MIN (f may be a small normalized
 				// float, a denormalized float or a zero).
 				//
-				// We convert f to a _halfGTX zero.
+				// We convert f to a half zero.
 				//
 
 				return 0;
@@ -162,7 +162,7 @@ namespace detail
 			// E is between -10 and 0.  F is a normalized float,
 			// whose magnitude is less than __half_NRM_MIN.
 			//
-			// We convert f to a denormalized _halfGTX.
+			// We convert f to a denormalized half.
 			// 
 
 			m = (m | 0x00800000) >> (1 - e);
@@ -180,7 +180,7 @@ namespace detail
 				m += 0x00002000;
 
 			//
-			// Assemble the _halfGTX from s, e (zero) and m.
+			// Assemble the half from s, e (zero) and m.
 			//
 
 			return hdata(s | (m >> 13));

+ 6 - 0
glm/gtc/constants.inl

@@ -34,6 +34,12 @@ namespace glm
 		return std::numeric_limits<T>::epsilon();
 	}
 
+	template <>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR half epsilon()
+	{
+		return half(1.19209290e-007);
+	}
+
 	template <typename T>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR T zero()
 	{

+ 3 - 1
test/gtc/gtc_constants.cpp

@@ -14,7 +14,9 @@ int main()
 {
 	int Error(0);
 
-    
+	float MinHalf = 0.0f;
+	while (glm::half(MinHalf) == glm::half(0.0f))
+		MinHalf += std::numeric_limits<float>::epsilon();
 
 	return Error;
 }

+ 5 - 5
test/gtc/gtc_epsilon.cpp

@@ -20,31 +20,31 @@ int test_equal()
 	{
 		T A = glm::epsilon<T>();
 		T B = glm::epsilon<T>();
-		Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
+		Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
 	}
 
 	{
 		T A(0);
 		T B = T(0) + glm::epsilon<T>();
-		Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
+		Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
 	}
 
 	{
 		T A(0);
 		T B = T(0) - glm::epsilon<T>();
-		Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
+		Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
 	}
 
 	{
 		T A = T(0) + glm::epsilon<T>();
 		T B = T(0);
-		Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
+		Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
 	}
 
 	{
 		T A = T(0) - glm::epsilon<T>();
 		T B = T(0);
-		Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
+		Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
 	}
 
 	return Error;