瀏覽代碼

Fixed vector based ULP functions

Christophe Riccio 14 年之前
父節點
當前提交
8e4dcece16
共有 2 個文件被更改,包括 59 次插入15 次删除
  1. 27 15
      glm/gtx/ulp.inl
  2. 32 0
      test/gtx/gtx-ulp.cpp

+ 27 - 15
glm/gtx/ulp.inl

@@ -54,42 +54,54 @@ namespace ulp
 	}
 
 	template <typename T>
-	inline detail::xvec2<T> ulp
+	inline std::size_t ulp
 	(
 		detail::xvec2<T> const & a,
 		detail::xvec2<T> const & b
 	)
 	{
-		return detail::xvec2<T>(
-				ulp(a[0], b[0]),
-				ulp(a[1], b[1]));
+        std::size_t ulps[] = 
+        {
+            ulp(a[0], b[0]),
+            ulp(a[1], b[1])
+        };
+
+        return glm::max(ulps[0], ulps[1])s;
 	}
 
 	template <typename T>
-	inline detail::xvec3<T> ulp
+	inline std::size_t ulp
 	(
 		detail::xvec3<T> const & a,
 		detail::xvec3<T> const & b
 	)
 	{
-		return detail::xvec3<T>(
-				ulp(a[0], b[0]),
-				ulp(a[1], b[1]),
-				ulp(a[2], b[2]));
+        std::size_t ulps[] = 
+        {
+            ulp(a[0], b[0]),
+            ulp(a[1], b[1]),
+            ulp(a[2], b[2])
+        };
+
+        return glm::max(glm::max(ulps[0], ulps[1]), ulps[2]);
 	}
 
 	template <typename T>
-	inline detail::xvec4<T> ulp
+	inline std::size_t ulp
 	(
 		detail::xvec4<T> const & a,
 		detail::xvec4<T> const & b
 	)
 	{
-		return detail::xvec4<T>(
-				ulp(a[0], b[0]),
-				ulp(a[1], b[1]),
-				ulp(a[2], b[2]),
-				ulp(a[3], b[3]));
+        std::size_t ulps[] = 
+        {
+            ulp(a[0], b[0]),
+            ulp(a[1], b[1]),
+            ulp(a[2], b[2]),
+            ulp(a[3], b[3])
+        };
+
+        return glm::max(glm::max(ulps[0], ulps[1]), glm::max(ulps[2], ulps[3]));
 	}
 
 }//namespace ulp

+ 32 - 0
test/gtx/gtx-ulp.cpp

@@ -0,0 +1,32 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Created : 2011-04-26
+// Updated : 2011-04-26
+// Licence : This source is under MIT licence
+// File    : test/gtx/ulp.cpp
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include <glm/glm.hpp>
+#include <glm/gtx/ulp.hpp>
+#include <iostream>
+
+int test_ulp_float()
+{
+	std::size_t A = ulp(0.01, 0.02);
+	std::size_t B = ulp(glm::vec2(0.01), glm::vec2(0.02));
+	std::size_t C = ulp(glm::vec3(0.01), glm::vec3(0.02));
+	std::size_t D = ulp(glm::vec4(0.01), glm::vec4(0.02));
+	std::cout << "glm::ulp test: " << A << std::endl;
+	std::cout << "glm::ulp test: " << B << std::endl;
+	std::cout << "glm::ulp test: " << C << std::endl;
+	std::cout << "glm::ulp test: " << D << std::endl;
+	return 0;
+}
+
+int main()
+{
+	test_ulp_float();
+}
+
+