mirror of
https://github.com/g-truc/glm.git
synced 2024-11-10 12:41:54 +00:00
Clean up half old cast operators and added counter ops tests
This commit is contained in:
parent
fc30641140
commit
bf698ec3e6
@ -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;
|
||||
}
|
||||
|
||||
|
@ -72,15 +72,47 @@ int test_half_arithmetic_unary_ops()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::half A(2.0f);
|
||||
glm::half B(3.0f);
|
||||
{
|
||||
glm::half A(2.0f);
|
||||
glm::half B(3.0f);
|
||||
A += B;
|
||||
Error += (A == glm::half( 5.0f) ? 0 : 1);
|
||||
}
|
||||
|
||||
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(-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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user