Browse Source

Clean up half old cast operators and added counter ops tests

Christophe Riccio 14 years ago
parent
commit
bf698ec3e6
2 changed files with 86 additions and 32 deletions
  1. 2 23
      glm/core/type_half.inl
  2. 84 9
      test/core/core_type_half.cpp

+ 2 - 23
glm/core/type_half.inl

@@ -275,27 +275,6 @@ namespace detail
 		return static_cast<U>(this->toFloat());
 	}
 
-	// Cast
-	//GLM_FUNC_QUALIFIER half::operator float()
-	//{
-	//	return toFloat();
-	//}
-
-	//GLM_FUNC_QUALIFIER thalf::operator float() const 
-	//{
-	//	return toFloat32(this->data);
-	//}
-
-	//GLM_FUNC_QUALIFIER half::operator double()
-	//{
-	//	return double(toFloat());
-	//}
-
-	//GLM_FUNC_QUALIFIER half::operator double() const
-	//{
-	//	return double(toFloat());
-	//}
-
 	// Unary updatable operators
 	GLM_FUNC_QUALIFIER thalf& thalf::operator= (thalf const & s)
 	{
@@ -330,14 +309,14 @@ namespace detail
 	GLM_FUNC_QUALIFIER thalf& thalf::operator++()
 	{
 		float Casted = toFloat32(data);
-		data = toFloat16(++Casted);
+		this->data = toFloat16(++Casted);
 		return *this;
 	}
 
 	GLM_FUNC_QUALIFIER thalf& thalf::operator--()
 	{
 		float Casted = toFloat32(data);
-		data = toFloat16(--Casted);
+		this->data = toFloat16(--Casted);
 		return *this;
 	}
 

+ 84 - 9
test/core/core_type_half.cpp

@@ -72,15 +72,47 @@ int test_half_arithmetic_unary_ops()
 {
 	int Error = 0;
 
-	glm::half A(2.0f);
-	glm::half B(3.0f);
-
-	Error += A + B == glm::half( 5.0f) ? 0 : 1;
-	Error += A - B == glm::half(-1.0f) ? 0 : 1;
-	Error += B - A == glm::half( 1.0f) ? 0 : 1;
-	Error += A * B == glm::half( 6.0f) ? 0 : 1;
-	Error += A / B == glm::half(2.0f / 3.0f) ? 0 : 1;
-	Error += B / A == glm::half(3.0f / 2.0f) ? 0 : 1;
+	{
+		glm::half A(2.0f);
+		glm::half B(3.0f);
+		A += B;
+		Error += (A == glm::half( 5.0f) ? 0 : 1);
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B(3.0f);
+		A -= B;
+		Error += (A == glm::half(-1.0f) ? 0 : 1);
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B(3.0f);
+		B -= A;
+		Error += (B == glm::half( 1.0f) ? 0 : 1);
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B(3.0f);
+		A *= B;
+		Error += (A == glm::half(6.0f) ? 0 : 1);
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B(3.0f);
+		A /= B;
+		Error += (A == glm::half(2.0f / 3.0f) ? 0 : 1);
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B(3.0f);
+		B /= A;
+		Error += (B == glm::half(3.0f / 2.0f) ? 0 : 1);
+	}
 
 	return Error;
 }
@@ -102,6 +134,48 @@ int test_half_arithmetic_binary_ops()
 	return Error;
 }
 
+int test_half_arithmetic_counter_ops()
+{
+	int Error = 0;
+
+	{
+		glm::half A(2.0f);
+		Error += A == glm::half(2.0f) ? 0 : 1;
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B = A++;
+		Error += B == glm::half(3.0f) ? 0 : 1;
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B = A--;
+		Error += B == glm::half(1.0f) ? 0 : 1;
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B = ++A;
+		Error += B == glm::half(3.0f) ? 0 : 1;
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B = --A;
+		Error += B == glm::half(1.0f) ? 0 : 1;
+	}
+
+	{
+		glm::half A(2.0f);
+		glm::half B = -A;
+		Error += B == glm::half(-2.0f) ? 0 : 1;
+	}
+
+	return Error;
+}
+
 int main()
 {
 	int Result = 0;
@@ -111,6 +185,7 @@ int main()
 	Result += test_half_relational();
 	Result += test_half_arithmetic_unary_ops();
 	Result += test_half_arithmetic_binary_ops();
+	Result += test_half_arithmetic_counter_ops();
 	
 	return Result;
 }