Browse Source

Fixed equal ULP variation when using negative sign #965

Christophe Riccio 6 years ago
parent
commit
919e72f5dd
3 changed files with 23 additions and 4 deletions
  1. 1 4
      glm/ext/scalar_relational.inl
  2. 1 0
      readme.md
  3. 21 0
      test/ext/ext_scalar_relational.cpp

+ 1 - 4
glm/ext/scalar_relational.inl

@@ -25,10 +25,7 @@ namespace glm
 
 		// Different signs means they do not match.
 		if(a.negative() != b.negative())
-		{
-			// Check for equality to make sure +0==-0
-			return a.mantissa() == b.mantissa() && a.exponent() == b.exponent();
-		}
+			return false;
 
 		// Find the difference in ULPs.
 		typename detail::float_t<genType>::int_type const DiffULPs = abs(a.i - b.i);

+ 1 - 0
readme.md

@@ -76,6 +76,7 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate)
 - Fixed GLM_HAS_CXX11_STL broken on Clang with Linux #926
 - Fixed Clang or GCC build due to wrong GLM_HAS_IF_CONSTEXPR definition #907
 - Fixed CUDA 9 build #910
+- Fixed equal ULP variation when using negative sign #965
 
 #### Deprecation:
  - Removed CMake install and uninstall scripts

+ 21 - 0
test/ext/ext_scalar_relational.cpp

@@ -71,6 +71,25 @@ static int test_notEqual_ulps()
 	return Error;
 }
 
+static int test_equal_sign()
+{
+	int Error = 0;
+
+	Error += !glm::equal(-0.0f, 0.0f, 2) ? 0 : 1;
+	Error += !glm::equal(-0.0, 0.0, 2) ? 0 : 1;
+
+	Error += !glm::equal(-1.0f, 2.0f, 2) ? 0 : 1;
+	Error += !glm::equal(-1.0, 2.0, 2) ? 0 : 1;
+
+	Error += !glm::equal(-0.00001f, 1.00000f, 2) ? 0 : 1;
+	Error += !glm::equal(-0.00001, 1.00000, 2) ? 0 : 1;
+
+	Error += !glm::equal(-1.0f, 1.0f, 2) ? 0 : 1;
+	Error += !glm::equal(-1.0, 1.0, 2) ? 0 : 1;
+
+	return Error;
+}
+
 int main()
 {
 	int Error = 0;
@@ -81,5 +100,7 @@ int main()
 	Error += test_equal_ulps();
 	Error += test_notEqual_ulps();
 
+	Error += test_equal_sign();
+
 	return Error;
 }