Fixed abs function for half based types

This commit is contained in:
Christophe Riccio 2012-11-06 01:23:14 +01:00
parent cdf5d19275
commit 1fb8bec873
3 changed files with 86 additions and 40 deletions

View File

@ -22,7 +22,7 @@
/// ///
/// @ref gtc_half_float /// @ref gtc_half_float
/// @file glm/gtc/half_float.hpp /// @file glm/gtc/half_float.hpp
/// @date 2009-04-29 / 2011-06-05 /// @date 2009-04-29 / 2012-11-06
/// @author Christophe Riccio /// @author Christophe Riccio
/// ///
/// @see core (dependence) /// @see core (dependence)
@ -416,6 +416,22 @@ namespace detail
/// @see gtc_half_float /// @see gtc_half_float
typedef detail::tmat4x4<detail::half> hmat4x4; typedef detail::tmat4x4<detail::half> hmat4x4;
/// Returns the absolute value of a half-precision floating-point value
/// @see gtc_half_float
half abs(half const & x);
/// Returns the absolute value of a half-precision floating-point two dimensional vector
/// @see gtc_half_float
hvec2 abs(hvec2 const & x);
/// Returns the absolute value of a half-precision floating-point three dimensional vector
/// @see gtc_half_float
hvec3 abs(hvec3 const & x);
/// Returns the absolute value of a half-precision floating-point four dimensional vector
/// @see gtc_half_float
hvec4 abs(hvec4 const & x);
/// @} /// @}
}// namespace glm }// namespace glm

View File

@ -22,7 +22,7 @@
/// ///
/// @ref gtc_half_float /// @ref gtc_half_float
/// @file glm/gtc/half_float.inl /// @file glm/gtc/half_float.inl
/// @date 2009-04-29 / 2011-06-05 /// @date 2009-04-29 / 2012-11-06
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -1006,4 +1006,34 @@ namespace detail
#endif//(GLM_COMPONENT == GLM_COMPONENT_CXX98) #endif//(GLM_COMPONENT == GLM_COMPONENT_CXX98)
}//namespace detail }//namespace detail
GLM_FUNC_QUALIFIER half abs(half const & x)
{
return float(x) >= float(0) ? x : -x;
}
GLM_FUNC_QUALIFIER hvec2 abs(hvec2 const & v)
{
return hvec2(
float(v.x) >= float(0) ? v.x : -v.x,
float(v.y) >= float(0) ? v.y : -v.y);
}
GLM_FUNC_QUALIFIER hvec3 abs(hvec3 const & v)
{
return hvec3(
float(v.x) >= float(0) ? v.x : -v.x,
float(v.y) >= float(0) ? v.y : -v.y,
float(v.z) >= float(0) ? v.z : -v.z);
}
GLM_FUNC_QUALIFIER hvec4 abs(hvec4 const & v)
{
return hvec4(
float(v.x) >= float(0) ? v.x : -v.x,
float(v.y) >= float(0) ? v.y : -v.y,
float(v.z) >= float(0) ? v.z : -v.z,
float(v.w) >= float(0) ? v.w : -v.w);
}
}//namespace glm }//namespace glm