Added cast from Half types to any scalar types
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2008-08-31
|
||||
// Updated : 2010-08-25
|
||||
// Updated : 2011-09-20
|
||||
// Licence : This source is under MIT licence
|
||||
// File : test/core/type_half.cpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -10,24 +10,107 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/half_float.hpp>
|
||||
|
||||
int test_half_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::half A(1.0f);
|
||||
Error += A.toFloat() == 1.0f ? 0 : 1;
|
||||
|
||||
glm::half B = glm::half(1.0f);
|
||||
Error += B.toFloat() == 1.0f ? 0 : 1;
|
||||
|
||||
glm::half C = B;
|
||||
Error += C.toFloat() == 1.0f ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_half_cast()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::half A(2.0f);
|
||||
Error += A.toFloat() == 2.0f ? 0 : 1;
|
||||
|
||||
glm::half B(2.0);
|
||||
Error += B.toFloat() == 2.0f ? 0 : 1;
|
||||
|
||||
glm::half C(2);
|
||||
Error += C.toFloat() == 2.0f ? 0 : 1;
|
||||
|
||||
float D(A);
|
||||
Error += D == 2.0f ? 0 : 1;
|
||||
|
||||
double E(A);
|
||||
Error += E == 2.0 ? 0 : 1;
|
||||
|
||||
int F(A);
|
||||
Error += F == 2.0 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_half_relational()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::half A(1.0f);
|
||||
glm::half B(2.0f);
|
||||
|
||||
Error += !(A == B) ? 0 : 1;
|
||||
Error += (A != B) ? 0 : 1;
|
||||
Error += (A <= B) ? 0 : 1;
|
||||
Error += (A < B) ? 0 : 1;
|
||||
Error += !(A >= B) ? 0 : 1;
|
||||
Error += !(A > B) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_half_arithmetic_binary_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;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Result = 0;
|
||||
|
||||
glm::half A(1.0f);
|
||||
glm::half B(2.0f);
|
||||
glm::half C = A + B;
|
||||
glm::half D(C);
|
||||
float E = D.toFloat();
|
||||
int F = C.toFloat();
|
||||
Result += float(F) == E ? 0 : 1;
|
||||
glm::half G = B * C;
|
||||
glm::half H = G / C;
|
||||
H += glm::half(1.0f);
|
||||
double J = H.toFloat();
|
||||
int I = H.toFloat();
|
||||
Result += J == 3.0 ? 0 : 1;
|
||||
Result += I == 3 ? 0 : 1;
|
||||
Result += test_half_ctor();
|
||||
Result += test_half_cast();
|
||||
Result += test_half_relational();
|
||||
Result += test_half_arithmetic_unary_ops();
|
||||
Result += test_half_arithmetic_binary_ops();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user