Added cast from Half types to any scalar types
This commit is contained in:
parent
edff9f7bf2
commit
fc30641140
@ -22,7 +22,7 @@
|
|||||||
///
|
///
|
||||||
/// @ref core
|
/// @ref core
|
||||||
/// @file glm/core/type_half.hpp
|
/// @file glm/core/type_half.hpp
|
||||||
/// @date 2008-08-17 / 2011-06-15
|
/// @date 2008-08-17 / 2011-09-20
|
||||||
/// @author Christophe Riccio
|
/// @author Christophe Riccio
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ namespace detail
|
|||||||
hdata toFloat16(float const & value);
|
hdata toFloat16(float const & value);
|
||||||
|
|
||||||
/// 16-bit floating point type.
|
/// 16-bit floating point type.
|
||||||
/// \ingroup gtc_half_float
|
/// @ingroup gtc_half_float
|
||||||
class thalf
|
class thalf
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -52,10 +52,8 @@ namespace detail
|
|||||||
GLM_FUNC_DECL explicit thalf(U const & s);
|
GLM_FUNC_DECL explicit thalf(U const & s);
|
||||||
|
|
||||||
// Cast
|
// Cast
|
||||||
//operator float();
|
template <typename U>
|
||||||
//GLM_FUNC_DECL operator float() const;
|
GLM_FUNC_DECL operator U() const;
|
||||||
//operator double();
|
|
||||||
//operator double() const;
|
|
||||||
|
|
||||||
// Unary updatable operators
|
// Unary updatable operators
|
||||||
GLM_FUNC_DECL thalf& operator= (thalf const & s);
|
GLM_FUNC_DECL thalf& operator= (thalf const & s);
|
||||||
|
@ -269,6 +269,12 @@ namespace detail
|
|||||||
data(toFloat16(float(s)))
|
data(toFloat16(float(s)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template <typename U>
|
||||||
|
GLM_FUNC_QUALIFIER thalf::operator U() const
|
||||||
|
{
|
||||||
|
return static_cast<U>(this->toFloat());
|
||||||
|
}
|
||||||
|
|
||||||
// Cast
|
// Cast
|
||||||
//GLM_FUNC_QUALIFIER half::operator float()
|
//GLM_FUNC_QUALIFIER half::operator float()
|
||||||
//{
|
//{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
|
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Created : 2008-08-31
|
// Created : 2008-08-31
|
||||||
// Updated : 2010-08-25
|
// Updated : 2011-09-20
|
||||||
// Licence : This source is under MIT licence
|
// Licence : This source is under MIT licence
|
||||||
// File : test/core/type_half.cpp
|
// File : test/core/type_half.cpp
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -10,24 +10,107 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/half_float.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 main()
|
||||||
{
|
{
|
||||||
int Result = 0;
|
int Result = 0;
|
||||||
|
|
||||||
glm::half A(1.0f);
|
Result += test_half_ctor();
|
||||||
glm::half B(2.0f);
|
Result += test_half_cast();
|
||||||
glm::half C = A + B;
|
Result += test_half_relational();
|
||||||
glm::half D(C);
|
Result += test_half_arithmetic_unary_ops();
|
||||||
float E = D.toFloat();
|
Result += test_half_arithmetic_binary_ops();
|
||||||
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;
|
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user